When deployed as a war file inside a container like Tomcat, Boot will return a 404 on the root path "/" if the welcome page is in the root of the war file, despite being found by WebMvcAutoConfiguration and WelcomePageHandlerMapping. If the war file looks like this:
- index.html
- WEB-INF/lib/...
- WEB-INF/classes/...
Then Boot will find the index.html:
o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: ServletContext resource [/index.html]
But when requesting the root path "/", we get:
2021-06-23 13:02:04.547 DEBUG 87091 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : GET "/demo/", parameters={} 2021-06-23 13:02:04.562 DEBUG 87091 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to ResourceHttpRequestHandler [Classpath [META-INF/resources/], Classpath [resources/], Classpath [static/], Classpath [public/], ServletContext [/]] 2021-06-23 13:02:04.565 DEBUG 87091 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler : Resource not found 2021-06-23 13:02:04.565 DEBUG 87091 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND
The issue seems to be this change introduced in 2.3.1. The WelcomePage works in 2.3.0, but not 2.3.1 and later.
When I change setAlwaysUseFullPath on this line to false in 2.5.1, it works again.
I've attached a small demo application demonstrating the issue. demo.zip
Comment From: wilkinsona
Thanks for the report and sample project. This sounds similar to https://github.com/spring-projects/spring-boot/issues/26773, although this is considerably simpler as the welcome page is being found by Spring Boot's own welcome page support rather than the hybrid approach in #26773 which relied on the container finding the welcome page and then Spring MVC serving the welcome page. I'm not yet sure what we can do about it.
Comment From: Surrin1999
In version 2.5.2, I encountered this problem too
Comment From: wilkinsona
This problem no longer occurs (tested with Spring Boot 3.2.6 and a war deployed to Tomcat 10.1.24).