6
votes

We're using Spring Boot and I've created a WAR, instead of a JAR, to deploy on a regular Tomcat server. All seems to work fine, except it appears that the context path isn't being set properly. Any relative paths in my index.html are not working.

When loading the app in a browser, this link,

<link type="text/css" rel="stylesheet" href="app.min.css" />

is attempted to be loaded from http://localhost:port/app.min.css instead of http://localhost:port/contextpath/app.min.css". Trying to set this in application.properties does not work as it looks like this value only works for the embedded Tomcat server.

1
Have you this line <link type="text/css" rel="stylesheet" href="app.min.css" /> in the source code displayed by your browser? - Nicolas Labrot
@NicolasLabrot, yes, it is. I can see network calls as the browser is trying to pull down the external links. - MD6380

1 Answers

6
votes

As you've already guessed the server.context-path property as well as all the other server.* properties apply to the embedded tomcat only. If you deploy to an external tomcat using WAR packaging you have to configure those values in the external tomcat itself.

The way we usually do this here is to have a context descriptor in ./conf/Catalina/localhost/ with a name that equals your expected context path, i.e. contextpath.xml according to the docs.