MetallicPriest
MetallicPriest

Reputation: 30765

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:

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.

Upvotes: 11

Views: 9299

Answers (2)

Milan Desai
Milan Desai

Reputation: 1306

You can define Jvm Argument -Dspring.profiles.active=<PROFILE> on server start up file (.bat/.sh) depending on your environment.

Upvotes: 0

MetallicPriest
MetallicPriest

Reputation: 30765

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

Upvotes: 12

Related Questions