首页 > 解决方案 > Tomcat 未重定向到 index.html

问题描述

出于某种原因,我已部署到 tomcat 中的 Spring Boot War 没有为来自 index.html 的站点根目录提供服务。(index.html 位于上下文根目录)。

当我使用可执行战争时,一切正常 - https://domain.tld自动加载 index.html。出于某种原因,当我将相同的战争部署到 tomcat 并导航到https://domain.tld时,我得到了 Spring Boot 的 404 页面。不过,转到https://domain.tld/index.html可以正常工作。我"o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: ServletContext resource [/index.html]"在启动日志中看到了可执行战争和 tomcat 的日志。但是,在tomcat的访问日志中,有一个404并且没有重定向:GET / HTTP/2.0" 404 286

我的 web.xml 有以下内容,似乎没有在任何地方被覆盖。(全新的tomcat安装)

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

任何想法为什么会有不同的行为,以及如何解决它?在一天的大部分时间里,我一直在努力解决这个问题,但没有运气。

更新 1

打开跟踪日志,找到了分歧点,但不知道是什么意思:

可执行战争(成功)

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'

雄猫 (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}

标签: springspring-bootkotlintomcat

解决方案


推荐阅读