Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring-Boot war external Tomcat context path

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.

like image 716
MD6380 Avatar asked Apr 14 '15 00:04

MD6380


People also ask

Where is Tomcat context path?

The context path refers to the location relative to the server's address which represents the name of the web application. By default, Tomcat derives it from the name of the deployed war-file. So if we deploy a file ExampleApp. war, it will be available at http://localhost:8080/ExampleApp.

Can we use external Tomcat in spring boot?

Deploying Spring Boot war file on External TomcatYou must have an apache tomcat installed on your computer. If not please download and install it. Once you installed and then go inside the folder of apache tomcat, for my case the path of tomcat is C:\Users\1302143\Downloads\apache-tomcat-8.5.

Where is context path in spring boot?

Just like many other configuration options, the context path in Spring Boot can be changed by setting a property, server. servlet. context-path.


1 Answers

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.

like image 111
ci_ Avatar answered Oct 10 '22 10:10

ci_