【发布时间】:2020-11-21 02:28:32
【问题描述】:
我有一个基于 this example 的 Spring Boot 应用程序。
现在的问题是如何在我的应用程序中添加重写规则,当用户访问根 URL 时添加 /index.html。
我的意思是当用户访问http://localhost:8080/my-app 或http://localhost:8080/my-app/ 时,我会将他或她重定向到http://localhost:8080/my-app/index.html。
我找到了 here 的东西,但不幸的是对我不起作用,而且似乎 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory 在 Spring Boot 2.3.1 中不再存在。
【问题讨论】:
-
https://stackoverflow.com/questions/29085295/spring-mvc-restcontroller-and-redirect 为
@RestController重定向提供了一些选项(标题具有误导性) -
您可以在stackoverflow.com/questions/7976173/…使用解决方案
-
@DoNhuVy:我测试过了,不幸的是它没有在url中注入
index.html。 -
我认为 Spring Boot,Spring MVC 可以返回这样的 URL
http://localhost:8080/foo/bar,而不是http://localhost:8080/foo/bar.html,因此没有必要。
标签: java spring-boot tomcat tomcat9