how to use Spring Boot profiles

The Solution to how to use Spring Boot profiles is

I'm not sure I fully understand the question but I'll attempt to answer by providing a few details about profiles in Spring Boot.

For your #1 example, according to the docs you can select the profile using the Spring Boot Maven plugin using -Drun.profiles.

Edit: For Spring Boot 2.0+ run has been renamed to and run.profiles has been renamed to

mvn spring-boot:run

From your #2 example, you are defining the active profile after the name of the jar. You need to provide the JVM argument before the name of the jar you are running.

java -jar XXX.jar

General info:

You mention that you have both an application.yml and a application-dev.yml. Running with the dev profile will actually load both config files. Values from application-dev.yml will override the same values provided by application.yml but values from both yml files will be loaded.

There are also multiple ways to define the active profile.

You can define them as you did, using when running your jar. You can also set the profile using a SPRING_PROFILES_ACTIVE environment variable or a system property.

More info can be found here:

~ Answered on 2016-10-15 16:01:49

Most Viewed Questions: