In this web application with Spring, I created several application-property files for different deploy environment. They specify different db connection configs.
application-dev.properties
application-qa.properties
application-stg.properties
application-prod.properties
The recommended way according to spring doc is to set spring.profiles.active as JVM option at run time, for example:
-Dspring.profiles.active=prod
However what should I do for deploying the application as war using mvn install. How should I set the spring profile? I am using Eclipse.
EDIT: I set the JVM option under . It does not seem to get picked up by maven when I deploy it as a war though since I got the following error from tomcat:
Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception
To configure Profiles in eclipse tomcat you have to add one parameter in VM arguments. For that you have to go run -> configurations and choose your Tomcat server then add “-Dspring. profiles. active=dev” to VM arguments.
The solution would be to create more property files and add the "profile" name as the suffix and configure Spring Boot to pick the appropriate properties based on the profile. Then, we need to create three application. properties : application-dev.
Use @Profile on a Bean Let's start simple and look at how we can make a bean belong to a particular profile. We use the @Profile annotation — we are mapping the bean to that particular profile; the annotation simply takes the names of one (or multiple) profiles.
Under Run Configuration > go to Environments tab and then add your property values for more please refer image below :Eclipse Environment SetUp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With