[英]Spring Boot/Gradle/Tomcat setting context path to something other than the .war name
I'm using Spring Boot and Gradle to create a war. 我正在使用Spring Boot和Gradle来制造战争。
war {
baseName = 'foo'
version = '0.1.0'
}
As the war task has a version number the generated war name is foo-0.1.0.war
and so when deployed to Tomcat the context path is http://localhost/foo-0.1.0/
由于war任务具有版本号,因此生成的war名称为
foo-0.1.0.war
,因此当部署到Tomcat时,上下文路径为http://localhost/foo-0.1.0/
I'd like to use the context path ' bar ' omitting the version number and using a different path. 我想使用上下文路径' bar '省略版本号并使用不同的路径。
http://localhost/bar
Is this possible using a Spring annotation? 这是否可以使用Spring注释? I've tried changing the
@RequestMapping
but this only changes the context to http://localhost/foo-0.1.0/bar
我已经尝试更改
@RequestMapping
但这只会将上下文更改为http://localhost/foo-0.1.0/bar
Following the answers here and here tried adding a context xml snippet to <catalina_home>/conf/Catalina/localhost/
按照这里的答案, 这里尝试将上下文xml片段添加到
<catalina_home>/conf/Catalina/localhost/
<Context docBase="/foo-0.1.0" path="/bar" reloadable="true"> </Context>
but although Tomcat is be undeploying /foo-0.1.0 I get the error: 但是虽然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.
Have I configured the Context incorrectly? 我是否错误地配置了Context?
If setting the context is the correct solution how do I add it to my project as spring boot appears to generate the web-inf folder when the application is compiled? 如果设置上下文是正确的解决方案,我如何将其添加到我的项目中,因为春天启动似乎在编译应用程序时生成web-inf文件夹?
I've tried adding context.xml
to /src/main/webapp/META-INF
and although its included in the war it doesn't change the context path 我已经尝试将
context.xml
添加到/src/main/webapp/META-INF
,虽然它包含在战争中它不会改变上下文路径
The root cause of the problem was using the Manger GUI to deploy the application, it seems that using the "WAR file to deploy" 'tool' uses the war name even if a context is provided 问题的根本原因是使用Manger GUI来部署应用程序,使用“WAR文件部署”'工具'似乎使用war名称即使提供了上下文
Using the Gradle Cargo plugin I've been able to deploy the application as required using a context.xml in \\src\\main\\resources
and using a context in build.gradle 使用Gradle Cargo插件我已经能够使用
\\src\\main\\resources
的context.xml并使用build.gradle中的上下文根据需要部署应用程序
cargo {
containerId = 'tomcat7x'
port = 80
deployable {
context = 'bar'
}
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.