Reputation: 31225
I made a Spring-Boot application that I want to run in an external tomcat 8.
In a Spring-Boot application , the context-path can be chosen using the property server.context-path
in application.properties
but as I am using an external tomcat 8, this property is not used.
Hence, I took a look at the tomcat-8 documentation which states:
If you want to deploy a WAR file or a directory using a context path that is not related to the base file name then one of the following options must be used to prevent double-deployment:
- Disable autoDeploy and deployOnStartup and define all Contexts in server.xml
- Locate the WAR and/or directory outside of the Host's appBase and use a context.xml file with a docBase attribute to define it.
As I do not want to pollute server.xml
, I chose the second option. Hence, I located the war in /home/myuser/myapp/application-1.0.0.war
and I placed a context file name application-1.0.0.xml
under conf/Catalina/localhost
. This file contains only those 2 lines :
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/myapp" docBase="/home/myuser/myapp"/>
I can see in the logs that tomcat8 starts successfully, the application appears to be deployed in the tomcat manager but :
/application-1.0.0
instead of /myapp
. application-1.0.0
appears in the work
directory but stays empty.Note : I know that the war is correct because it works if I place it in the webapp
directory (with the default context path though).
Note : If I rename application-1.0.0.xml
to foo.xml
, the tomcat manager shows that the application is deployed under context-path /foo
(but it is still never started).
Any ideas?
Upvotes: 5
Views: 3600
Reputation: 65
If it helps someone, following (placed inside conf\Catalina\localhost\service-discovery.xml) works for me on on Tomcat 9
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/service-discovery" docBase="D:/Projects/codebase/apps/service-discovery/target/service-discovery.war"/>
Upvotes: 0
Reputation: 31225
Found the answer :
path
of the context file is indeed ignored : This attribute must only be used when statically defining a Context in server.xml. In all other circumstances, the path will be inferred from the filenames used for either the .xml context file or the docBase.
docBase
attribute, I misinterpreted the following sentence : Locate the WAR and/or directory outside of the Host's appBase and use a context.xml file with a docBase attribute to define it.
Actually, in docBase
, I put the path to the directory which contains the war instead of the path to the war itself.
Upvotes: 2