Reputation: 87
Using NetBeans 8.1.
I have this simple java Spring Boot project without any beans or persistency. Two java classes in the same package.
@SpringBootApplication
public class SpringSimpleTestApplication {
public static void main(String[] args) {
SpringApplication.run(SpringSimpleTestApplication.class, args);
}
}
@Controller
public class WebController {
@RequestMapping("/")
public String index(){
return "index";
}
}
And a "index.html" file under src/main/resources->templates
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Test</h1>
</body>
</html>
When i run it i have no errors but when i go to http://localhost:8080/ I have the Whitelabel Error Page :
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Feb 09 01:53:26 CET 2017
There was an unexpected error (type=Not Found, status=404).
No message available
Upvotes: 0
Views: 719
Reputation:
First, whereas index.html
is a static resource, it belongs under src/main/resources/static
, not src/main/resources/templates
.
Second, you don't need a request mapping for static resources. They just work.
So, move index.html
, delete WebController
, and it will work.
Upvotes: 4
Reputation: 1803
You place your html in a wrong directory. It is reason why you get this error.
In Spring Boot project, the default directory store html file to be src/main/webapp. However, it's hard show it with you here. I found this from the tutorial Spring Boot Maven Example Hello World with JSP
If you create Spring Boot project with Thymeleaf, the default directory is exactly src/main/resources/templates. You can refer to the post Spring Boot Thymeleaf Hello World Example
I just build project with both of cases, it works normally. Hope this help
Upvotes: 0