1

For some reason, my spring boot war which I have deployed into tomcat is not serving request for the site root from index.html. (index.html is at the context root).

When I use an executable war, everything works fine - https://domain.tld automatically loads index.html. For some reason when I deploy the same war to tomcat, and navigate to https://domain.tld, I get Spring Boot's 404 page. Going to https://domain.tld/index.html works fine, though. I see "o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: ServletContext resource [/index.html]" in the startup log for both the executable war and tomcat's log. However, in tomcat's access log, there is a 404 and no redirect: GET / HTTP/2.0" 404 286

My web.xml has the following, which doesn't appear to be overridden anywhere. (Fresh tomcat install)

<welcome-file-list>
  <welcome-file>index.html</welcome-file>
  <welcome-file>index.htm</welcome-file>
  <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

Any ideas why there is different behavior, and how to fix it? I've been banging my head against this for most of the day with no luck.

Update 1

Turned on trace logging and found the point of divergence, but have no idea what it means:

Executable war (successful)

2020-09-23 01:34:21.348 TRACE 11076 --- [nio-8443-exec-3] o.s.web.servlet.DispatcherServlet        : GET "/", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
2020-09-23 01:34:21.353 TRACE 11076 --- [nio-8443-exec-3] o.s.b.a.w.s.WelcomePageHandlerMapping    : Mapped to HandlerExecutionChain with [ParameterizableViewController [view="forward:index.html"]] and 3 interceptors
2020-09-23 01:34:21.362 TRACE 11076 --- [nio-8443-exec-3] o.s.b.f.s.DefaultListableBeanFactory     : Invoking afterPropertiesSet() on bean with name 'forward:'
2020-09-23 01:34:21.362 TRACE 11076 --- [nio-8443-exec-3] o.s.b.f.s.DefaultListableBeanFactory     : Returning cached instance of singleton bean 'metaDataSourceAdvisor'

Tomcat (404)

2020-09-23 01:29:05.816 TRACE 10413 --- [apr-8443-exec-1] o.s.web.servlet.DispatcherServlet        : GET "/", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
2020-09-23 01:29:05.818 TRACE 10413 --- [apr-8443-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 3 interceptors
2020-09-23 01:29:05.818 DEBUG 10413 --- [apr-8443-exec-1] o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found
2020-09-23 01:29:05.818 DEBUG 10413 --- [apr-8443-exec-1] w.c.HttpSessionSecurityContextRepository : SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
2020-09-23 01:29:05.818 TRACE 10413 --- [apr-8443-exec-1] o.s.web.servlet.DispatcherServlet        : No view rendering, null ModelAndView returned.
2020-09-23 01:29:05.818 DEBUG 10413 --- [apr-8443-exec-1] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND, headers={masked}
pepper
  • 21
  • 2
  • Please check the link, it may help - https://stackoverflow.com/questions/47908312/create-war-file-from-springboot-project-in-eclipse/47912809#47912809 – Neeraj Benjwal Sep 23 '20 at 06:05
  • @NeerajBenjwal Didn't have anything relevant - that part of the process is working fine. – pepper Sep 23 '20 at 17:36
  • any update on this? @pepper any change you still know how you fixed that? – wollsi Nov 12 '21 at 16:08
  • where is your `index.html` (relatively to your project structure/war)? – xerx593 May 05 '23 at 15:36
  • ...in `src/main/webapp` (maven-war-default) or in `src/mein/resources/static` (spring-boot-default)? I recommend the latter! – xerx593 May 06 '23 at 23:50

1 Answers1

0

I had a similar issue, when having index.html at the root of the WAR.

Spring Boot has indeed the ability to manage welcome pages. But it will search index.html in configured locations.

These locations can be configured with the property spring.web.resources.static-locations. Defaults to [classpath:/META-INF/resources/, classpath:/resources/, classpath:/static/, classpath:/public/].

An old article (2013) from Spring Blog describing how to serve static content : Serving Static Web Content with Spring Boot.

Also a guide to Add a Home Page in Spring Boot, with index.html.

Guillaume Husta
  • 4,049
  • 33
  • 40