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

MetallicPriest :

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.

MetallicPriest :

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=88759&siteId=1