简体   繁体   中英

Spring Boot/Eclipse index.html: There was an unexpected error (type=Not Found, status=404)

I'm following this tutorial to integrate Spring Boot with AngularJS:

https://dzone.com/articles/java-8-springboot-angularjs-bootstrap-springdata-j

I built the Spring Boot starter with STS in Eclipse/Photon. My Eclipse project looks like this:

在此处输入图片说明 My "Home" Controller looks like this:

package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {
    @RequestMapping("/home")
    public String home() {
        return "index";
    }
}

Per the screenshot above, I have an "index.html" in src/main/resources/static/views.

My application.properties defines spring.mvc.view.prefix and .suffix:

spring.mvc.view.prefix = /views/
spring.mvc.view.suffix = .html

There are no errors or warnings when I right-click the Eclipse project and "Run As > Spring App".

But when I browse to localhost:8080/home, I get:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sat Nov 03 13:40:19 PDT 2018
There was an unexpected error (type=Not Found, status=404).
No message available

Q: Why am I getting a "404" trying to access "/home"?

Q: Is there anything "special" I need to do in Eclipse, with my Eclipse project?

Q: What are some good strategies for troubleshooting?

Thank you in advance!

I believe you are not using templating engine such as thymeleaf .

Try the following and it should fix your problem.

  1. move your index.html to src/main/resources/static . This is the location from where static resources like HTML file will be served automatically.
  2. You can remove those two lines that you define on application.properties file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM