简体   繁体   中英

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM