Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify a profile when deploying a Spring boot war file to Tomcat?

At the moment, all my properties are defined in the file src/main/resources/application.properties. However, I would like to have properties files relating to different profiles in the src/main/resources/config folder, and I want to be able to choose any of them. such as:

  • application-DEV.properties
  • application-TEST.properties
  • application-SERVER1.properties

So, the question is how to select these properties. If I was compiling to a jar file, I could do that easily by specifiying the profile when running the jar file, but here I just copy the generated war file to a Tomcat webapps directory.

like image 246
MetallicPriest Avatar asked May 02 '19 08:05

MetallicPriest


1 Answers

Well, I've found a way to do that. In the conf directory of Tomcat, add this line to the file catalina.properties there.

spring.profiles.active=<YOUR_PROFILE>

Replace <YOUR_PROFILE> here of course with your profile's name. For example if you are using application-TEST.properties, it would be the following.

spring.profiles.active=TEST
like image 58
MetallicPriest Avatar answered Sep 27 '22 18:09

MetallicPriest