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
Edit: For Spring Boot 2.0+
run has been renamed to
run.profiles has been renamed to
mvn spring-boot:run -Dspring-boot.run.profiles=dev
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 -Dspring.profiles.active=dev XXX.jar
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
-Dspring.profiles.active when running your jar. You can also set the profile using a
SPRING_PROFILES_ACTIVE environment variable or a
spring.profiles.active system property.
More info can be found here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-set-active-spring-profiles
~ Answered on 2016-10-15 16:01:49