java 在容器 tomcat 服务器上更改已部署(Spring Boot)war 的上下文路径。所以它不是 demo-0.01-SNAPSHOT

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43856043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 07:46:07  来源:igfitidea点击:

Changing the context path of deployed (Spring Boot) war on a container tomcat server. So it is not demo-0.01-SNAPSHOT

javaspringtomcatspring-bootdeployment

提问by Denis

I have tried to deploy my site using many configurations to make it change from the war name being deployed. Is there a way to do this easily. The deployment will to a tomcat sitting somewhere else. e.g. bitnami instance

我尝试使用许多配置来部署我的站点,以使其更改为正在部署的War名称。有没有办法轻松做到这一点。部署将部署到位于其他地方的 tomcat。例如比特纳米实例

I have tried various combinations of settings in the application.properties but none make any difference:

我在 application.properties 中尝试了各种设置组合,但没有任何区别:

 server.servlet.context-path=/a
    server.servlet.path=/b
    spring.webservices.path=/c
    server.contextPath=/m

The war is called demo-0.0.01-SNAPSHOT.war and when dropped in the webapps directory it creates the same named directory and the site then has a /demo-0.0.01-SNAPSHOT path. I thought with the days of Spring Boot this would be easy now but a fool like me hasn't worked it out yet. Or do people just deploy embedded versions with tomcats and run them nowadays?

这场War被称为 demo-0.0.01-SNAPSHOT.war,当它被放入 webapps 目录时,它会创建相同的命名目录,然后该站点有一个 /demo-0.0.01-SNAPSHOT 路径。我认为在 Spring Boot 的时代,这现在很容易,但像我这样的傻瓜还没有解决。还是人们只是使用 tomcats 部署嵌入式版本并在现在运行它们?

(BTW I have tried the root.xml as well, no luck ... unless i did it wrong on my windows box, testing on my dev box first, linux for deployment)

(顺便说一句,我也尝试过 root.xml,没有运气......除非我在我的 Windows 机器上做错了,首先在我的开发机器上测试,用于部署的 linux)

Any help would be appreciated.

任何帮助,将不胜感激。

Thanks

谢谢

回答by davidxxx

The Spring Boot property to specify the context path of the application is : server.contextPath.
But the fact that you are deploying your WAR into a standalone Tomcat instance doesn't allow to use it.
In this configuration, you cannot use server.contextPathand other properties specific to the container (as for example server.port). These are designed to work with the embedded Tomcat instance.

用于指定应用程序上下文路径的 Spring Boot 属性是 : server.contextPath
但是,您将 WAR 部署到独立的 Tomcat 实例中这一事实不允许使用它。
在此配置中,您不能使用server.contextPath和 特定于容器的其他属性(例如server.port)。这些旨在与嵌入式 Tomcat 实例一起使用。

The standalone Tomcat instance keeps indeed the control on these facilities provided by Spring Boot. So you have to configure it from the configuration file of the standalone Tomcat (server.xml or ROOT.xml way generally).

独立的 Tomcat 实例确实保持对 Spring Boot 提供的这些设施的控制。所以你必须从独立Tomcat的配置文件(一般是server.xml或ROOT.xml方式)来配置它。

回答by acpuma

Adding finalNamesetting to pom.xmlfor maven will make the packaged war filename to it. For example.

finalName设置添加到pom.xmlfor maven 将使打包的 war 文件名成为它。例如。

<build>
...
<finalName>myapp</finalName>
</build>

The packaged filename will be myapp.war. When you deploy to tomcat it will set the context to the filename.

打包的文件名将是myapp.war。当您部署到 tomcat 时,它会将上下文设置为文件名。