I am using Spring Boot (2.5.6)'s Controller like this:
@Controller
public class WebController {
@GetMapping("/index")
public String indexPage () {
return "index";
}
}
And when I hit these two URLs:
http://localhost:8080/index
http://localhost:8080
Same Thymeleaf view index.html
is served. To my understanding on hitting http://localhost:8080
I should get - Whitelabel Error Page
.
In the past I have used something like this @RequestMapping(value = { "/", "/index" }, method = RequestMethod.GET)
extensively. What I am missing/overlooking here?
CodePudding user response:
Spring Boot, through auto-configuration, will add a WelcomePageHandlerMapping
. The WelcomePageHandlerMapping
will mimic the behavior of the welcome-page support in Servlet containers like Tomcat.
By default it will try to locate an index.html
in either the static
or template
directory and, if needed, use the available templating framework to render this page.