Spring Boot / Gradle / Tomcat将上下文路径设置为.war以外的名称 [英] Spring Boot/Gradle/Tomcat setting context path to something other than the .war name

查看:143
本文介绍了Spring Boot / Gradle / Tomcat将上下文路径设置为.war以外的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Boot和Gradle来创建一场战争。
$ b

  war {
baseName ='foo'
version ='0.1 .0'
}

由于战争任务有一个版本号,所以生成的战争名称是 foo-0.1.0.war 所以当部署到Tomcat时,上下文路径是 http://localhost/foo-0.1.0/



我想使用上下文路径' bar '省略版本号并使用不同的路径。 / p>

  http:// localhost / bar 

这可能使用Spring注释吗?我尝试过更改 @RequestMapping ,但这只会将上下文更改为 http://localhost/foo-0.1.0/bar



继答案我已经能够根据需要在 \src\main\resources 中使用context.xml部署应用程序,并使用上下文build.gradle

 货物{
containerId ='tomcat7x'
端口= 80

可部署{
context ='bar'
}
...
}


I'm using Spring Boot and Gradle to create a war.

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/

I'd like to use the context path 'bar' omitting the version number and using a different path.

http://localhost/bar

Is this possible using a Spring annotation? I've tried changing the @RequestMapping but this only changes the context to 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/

<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:

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?

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?

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

解决方案

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

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

cargo {
    containerId = 'tomcat7x'
    port = 80

    deployable {
        context = 'bar'
    }
...
}

这篇关于Spring Boot / Gradle / Tomcat将上下文路径设置为.war以外的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆