Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify spring.profiles.active when I run mvn install

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 run configuration. 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
like image 294
ddd Avatar asked Aug 22 '16 14:08

ddd


People also ask

How do I activate a spring boot profile when running from Eclipse?

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.

How do I select a profile in spring boot?

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.

How do you define beans for a specific profile?

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.


1 Answers

Under Run Configuration > go to Environments tab and then add your property values for more please refer image below :Eclipse Environment SetUp

like image 140
Arka Bandyopadhyay Avatar answered Sep 23 '22 15:09

Arka Bandyopadhyay