Changing the context path of deployed (Spring Boot

2019-02-05 10:58发布

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

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

 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?

(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)

Any help would be appreciated.

Thanks

2条回答
三岁会撩人
2楼-- · 2019-02-05 11:24

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.contextPath and other properties specific to the container (as for example server.port). These are designed to work with the embedded Tomcat instance.

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).

查看更多
ゆ 、 Hurt°
3楼-- · 2019-02-05 11:31

Adding finalName setting to pom.xml for maven will make the packaged war filename to it. For example.

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

查看更多
登录 后发表回答