简体   繁体   English

Spring Boot / Gradle / Tomcat将上下文路径设置为除.war名称之外的其他内容

[英]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名称即使提供了上下文

Manager  - 要部署的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.

相关问题 Undertow和Tomcat的Spring Boot .war上下文路径 - Spring Boot .war context path for Undertow and Tomcat 在Spring Boot Gradle中配置嵌入式tomcat上下文docBase和路径 - configure embedded tomcat context docBase and path in spring boot gradle 在容器tomcat服务器上更改已部署(Spring Boot)战争的上下文路径。 所以它不是demo-0.01-SNAPSHOT - Changing the context path of deployed (Spring Boot) war on a container tomcat server. So it is not demo-0.01-SNAPSHOT Spring Boot 上下文路径被外部 Tomcat 忽略 - Spring Boot Context Path Ignored With External Tomcat 覆盖 Spring 引导 / Tomcat 中的上下文路径 - Override Context Path in Spring Boot / Tomcat Spring boot WAR 部署到 Tomcat 并且缺少静态资源的上下文 - Spring boot WAR deployed to Tomcat and missing context for static resources 在tomcat7上以战争方式部署的Spring Boot应用程序失败,错误为“发现了多个名称为[org_apache_tomcat_websocket]的片段” - Spring boot app deployed as war on tomcat7 fails with error “More than one fragment with the name [org_apache_tomcat_websocket] was found” "设置上下文路径与 Tomcat 中的 WAR 版本名称无关" - Set context path irrespective for WAR version name in Tomcat Tomcat使用war name作为Spring启动的基本URL - Tomcat using war name as base url for Spring boot 春季引导战争到外部雄猫 - spring boot war to external tomcat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM