5

I would like to run my spring application two times, in parallel, on the same tomcat server. One time with a production profile and one time with a dev profile.

I also would like to build one single WAR for the two profiles.

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

What I need is a mean to activate a different profile on each of theses two applications, with the constraint that these two applications use a copy of the same WAR file and that the two applications should run in parallel.

So WebApplicationInitializer and web.xml seem not an option.

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
  • Use spring.proflies.active variable (either as a system variable or an application variable through the spring framework) to active the needed profile – dumitru Apr 01 '16 at 09:54
  • Both applications should run in parallel. How can I set both values in tomcat configuration files? – Ortomala Lokni Apr 01 '16 at 09:57
  • Check here http://stackoverflow.com/questions/26652264/tomcat-7-application-java-environment-variables-jndi-less or here http://stackoverflow.com/questions/16946814/different-environment-variables-per-war-in-tomcat – dumitru Apr 01 '16 at 10:10

1 Answers1

4

For the record:

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

Create a 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 set the spring.profiles.active property to dev,server for the application run by application-dev.war.

Thanks to this answer: https://stackoverflow.com/a/26653238/1807667

P.S.: With autoDeploy=true in server.xml, the configuration files disappear on tomcat restart.

Solution is to add <Context reloadable="true"> in <CATALINA_BASE>/conf/context.xml but beware that according to documentation :

This feature is very useful during application development, but it requires significant runtime overhead and is not recommended for use on deployed production applications.

and moreover using <Context reloadable="true"> does not solve fully the issue the configuration files still disappear for some restart.

P.S.2: There is no docBase attribute in the Context element, see this question.

Community
  • 1
  • 1
Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240