How to run two WAR files with different spring profiles on tomcat server?

I would like to run my spring application twice, in parallel, on the same tomcat server. Once with the production profile and once with the dev profile.

I would also like to create one WAR for two profiles.

I have successfully integrated profiles in my application with @Profile annotations. I have successfully deployed two WAR files on my tomcat server.

I need to activate a different profile in each of the two applications, with the restriction that these two applications use a copy of the same WAR file and that the two applications must run in parallel.

So WebApplicationInitializer and web.xml not an option.

+3
source share
1 answer

For the record:

To activate the dev spring profile in the application in application-dev.war

Create file <CATALINA_BASE>/conf/Catalina/localhost/application-dev.xml

With the following content:

 <Context> <Environment name="spring.profiles.active" value="dev,server" type="java.lang.String" override="false" /> </Context> 

This is the spring.profiles.active property for dev,server for the application running application-dev.war .

Thanks to this answer: fooobar.com/questions/45709 / ...

PS: With autoDeploy=true in server.xml configuration files disappear when you restart tomcat.

The solution is to add <Context reloadable="true"> to <CATALINA_BASE>/conf/context.xml , but be careful as per the documentation :

This feature is very useful when developing applications, but it requires a significant investment of time and is not recommended for deployed production applications.

and, in addition, using <Context reloadable="true"> does not completely solve the problem when the configuration files still disappear for some restart.

PS2: There is no docBase attribute in the Context element, see this question .

+3
source

Source: https://habr.com/ru/post/1273936/


All Articles