I use SpringBoot 1.5.9 and created src/main/resources/static/index.html
:
<!DOCTYPE html><html><head><meta charset="utf-8"/>
<title>Home</title></head>
<body><h2>Hello World!!</h2></body>
</html>
My simple controller is handling "/" and forwarding to index.html:
@Controller
public class MyController {
@RequestMapping("/")
public String home(Model model) {
System.out.println("In MyController!!!");
return "index";
}}
However when after I run my main method from:
@SpringBootApplication
public class MySpringBoot2Application {
public static void main(String[] args) {
SpringApplication.run(MySpringBoot2Application.class, args);
}
}
and I point my browser to: http://localhost:8080/
I am getting:
Whitelabel Error Page-There was an unexpected error (type=Not Found, status=404)
But, if i try to access the page directly - it works fine: http://localhost:8080/index.html
Based on the SpringBoot documentation the static content under src/main/resources/static/
should be rendered.
If I create folder src/main/resources/templates/
and put my index.html
there, and also include spring-boot-starter-thymeleaf dependency in my pom.xml then everything works good. However I am puzzled why this basic rendering of src/main/resources/static/index.html
is not working. Any help is appreciated.
Just found the solution: the controller MyController should specify the file extension:
return "index.html";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With