6

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.

MD6380
  • 1,007
  • 4
  • 13
  • 26

1 Answers1

7

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.

ci_
  • 8,594
  • 10
  • 39
  • 63
  • Is there a way to do this through application code or configuration instead of through Tomcat server configuration? – MD6380 Apr 14 '15 at 16:08
  • In the contextpath.xml file, i have the path attribute set. I've verified in the catalina.log file that the file is read in and the path is set, but it doesn't work. When accessing the main index.html page, the links are attempted to be downloaded from http://localhost:port/filename instead of http://localhost:port/contextpath/filename. Does spring-boot somehow handle this differently? – MD6380 Apr 14 '15 at 18:39
  • 1
    I'm beginning to think I read your question incorrectly, I'll leave my answer there for the moment, and edit it once I figure out what's going on. – ci_ Apr 14 '15 at 19:44
  • https://github.com/spring-projects/spring-boot/issues/4682 I think the context needs to be set in the external tomcat configuration – Phani Kumar Bhamidipati Feb 02 '16 at 12:14
  • How does it work with `server.context-path` property? I suppose this property is overwritten with the context path read from the servlet container. So you need to set it just for local deployments(embedded) so it will work with the same path as on the external server(where it is set the same) – Zveratko Feb 09 '16 at 07:06