拥有 spring boot 1.3.x 应用程序,并在 application.properties 中定义了 server.context-path=/mypath ,并按照 Java Spring Boot: How to map my app root (“/”) to index.html? 中的定义重定向请求
使用 viewControllerRegistry.addViewController("/").setViewName("forward:/index.html") 将 URL example.com/mypath 映射到 example.com/mypath/index.html 的请求
还需要将 URL example.com/的请求自动重定向到 example.com/mypath
这可以通过定义 server.context-path=/mypath 来实现吗?更愿意让 Spring Boot 进行重定向,而不是引入 nginx 或 apache httpd,但不知道如何实现这一点。研究了删除上下文路径,但这会导致对完善的大型代码库进行太多更改。
最佳答案
也许有更好的解决方案,但您可以将应用程序映射到 example.com
(不要设置server.context-path
)并创建一个 Controller 监听基本 URL 并将所有请求重定向到 example.com/mypath
,将所有其他 Controller 映射到 example.com/maypath/somecontroller1
,example .com/maypath/somecontroller2
等等。
关于java - 将应用程序根目录 ("/")映射到我的上下文根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34601040/