I stuck with this simple MVC example. When I start the App and go to localhost:8080, I got "Whitelabel Error Page", even I created "index.html" in "src/main/resources/templates". I also add @RequestMapping("/") on my index method. I can't find the problems.
IndexController.java
:
package controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping("/")
public String index(){
return "index";
}
}
SpringmvcApplication.java
:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringmvcApplication {
public static void main(String[] args) {
SpringApplication.run(SpringmvcApplication.class, args);
}
}
index.html
- under "src/main/resources/templates":
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
<title>Hello Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Hello World</h1>
<h2>This is my Thymeleaf index page.</h2>
</body>
</html>