2

I have a spring boot web application that deploys as a WAR. Right now when I deploy it to my Tomcat 7 server, it uses the name of the war file as the context, such as /myartifactid-1.5.4.SNAPSHOT/. I want to specify the context-path, but

server.contextPath=/mywebapp

seems to only work for embedded tomcat. I've added a META-INF/context.xml with only this

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="false" path="/mywebapp" />

but that hasn't had any effect.

EDIT: This is NOT a spring-boot issue, but instead related to how NetBeans behaves differently from Eclipse. NetBeans apparently recognizes the context path parameter in context.xml, but Eclipse doesn't. In Eclipse you have to modify the Web Projects Settings to set the context path. Changing Tomcat context path of web project in Eclipse

Community
  • 1
  • 1
gyoder
  • 4,530
  • 5
  • 29
  • 37
  • It's not necessarily related to differences in the behaviour of Eclipse and Netbeans: I'm having the same problem when deploying without an IDE. – Rich Jul 08 '15 at 12:16

2 Answers2

0

Since you are packaging your Spring Boot application as a war (as opposed to a jar with an embedded tomcat container) the context path will be the name of the war.

For example if you name your packaged application mywebapp.war and you place it under Tomcat's webapps, it will be available under /mywebapp

geoand
  • 60,071
  • 24
  • 172
  • 190
0

when the war does not have the same name with the project, the application will not be accessible via the context path on the tomcat, to fix this you need to go to the POM.xml change the name of package to match the context path name

server.servlet.context-path=/virtualcard 

    <groupId>com.test.csc.virtualcard</groupId>
        <artifactId>virtualcard</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>war</packaging>
        <name>virtualcard</name>

then the war will be: virtualcard.war