Search code examples
spring-boottomcattomcat8

Multiple web applications in one tomcat instance start with a properties file from another applications


We have multiple web applications in one tomcat instance on 1 server, all running a spring-boot application inside.

Whenever we start tomcat and it starts to boot up all the spring-boot applications we mostly see that each application might use property files/settings from another application.

What especially happens is that we see it sometimes use the database information from other applications being used, resulting in a database which holds tables from other applications. This is scary since we might start a database migration or something.

We also see that the logs are written to the wrong project log file.

We define these settings using a application.properties like (or sometimes application-test.properties or application-secret.properties):

spring.datasource.username
spring.datasource.password
logging.file.name

Anyone have an idea why this is happening?


Solution

  • We found 2 possible causes for this behavior:

    1. if Tomcat is started in a directory where application property files are present, or where application property files are placed in a /config subdirectory, like a WEB-INF/classes directory, these application property files are used by every Spring Boot application deployed in the tomcat instance. To fix this, make sure the Tomcat start script changes the working directory to a directory not containing application property files.
    2. if the 'startStopThreads' attribute of the Tomcat Engine element in server.xml is set to values higher than 1, Spring Boot applications seem to occasionally and randomly use application property files of other Spring Boot applications deployed in the Tomcat instance. When 'startStopThreads' is set to 1, we don't see this behavior.