【发布时间】:2015-09-09 02:25:09
【问题描述】:
我正在使用 Spring Boot 和 Gradle 来创建战争。
war {
baseName = 'foo'
version = '0.1.0'
}
因为战争任务有一个版本号,所以生成的战争名称是foo-0.1.0.war,所以当部署到Tomcat时,上下文路径是http://localhost/foo-0.1.0/
我想使用上下文路径“bar”省略版本号并使用不同的路径。
http://localhost/bar
这可以使用 Spring 注释吗?我试过更改@RequestMapping,但这只会将上下文更改为http://localhost/foo-0.1.0/bar
按照here 和here 的答案尝试将上下文xml sn-p 添加到<catalina_home>/conf/Catalina/localhost/
<Context docBase="/foo-0.1.0" path="/bar" reloadable="true"> </Context>
但是尽管 Tomcat 正在取消部署 /foo-0.1.0 我得到了错误:
WARNING: A docBase C:\tools\apache-tomcat-7.0.53\webapps\foo-0.1.0 inside the host appBase has been specified, and will be ignored.
我是否错误地配置了上下文?
如果设置上下文是正确的解决方案,我该如何将它添加到我的项目中,因为 spring boot 在编译应用程序时似乎会生成 web-inf 文件夹?
我尝试将context.xml 添加到/src/main/webapp/META-INF,虽然它包含在战争中,但它不会改变上下文路径
【问题讨论】:
-
将 context.xml 文件添加到包含路径的 wars 元信息目录中。或者不要部署到 tomcat,使用嵌入式服务器,只需在
application.properties中设置server.context-path=/bar。 -
@M.Deinum 我无法使用嵌入式服务器,因为我需要将战争部署到包含其他应用程序的生产环境中。我已经尝试过 meta-inf 方法,但它似乎不起作用 - 可能文件有问题
-
当把它放在 META-INF 中时,请确保你不需要其他 context.xml。如果您这样做,它将被忽略,因为服务器上的优先!
-
@M.Deinum 好建议,我已经检查过了,
\conf\Catalina\localhost中没有其他上下文 xml sn-ps -
这种方法行不通,
This attribute must only be used when statically defining a Context in server.xml. In all other circumstances, the path will be inferred from the filenames used for either the .xml context file or the docBase.(来自 tomcat 指南)。因此,唯一的解决方案似乎是重命名您的战争或将其添加到 server.xml 的 Host 元素中。
标签: java spring tomcat gradle spring-boot