spring - 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}
解决方案
推荐阅读
- python - 拟合 sigmoid 曲线 (Python)
- java - 有没有办法在画布循环中制作图像并一遍又一遍地重绘自己?
- javascript - 上传包含空子文件夹的文件夹
- python - 在 panda.Dataframe 中有效地有条件地重新定位元素
- debugging - Redis Lua 调试器:禁用大数的科学记数法
- python - 如何获得没有元音的单词列表?
- javascript - 为什么我不能从当前状态中获取一个值并在我的 useState 挂钩中使用它?
- python - 断言类方法
- web-scraping - BS4 webscraping 从多个元素中获取文本
- python - beautifulsoup 不抓取电子邮件,但抓取格式