I have a spring boot application.
I have three profiles in my application-> development, staging and production. So I have 3 files
you can use the following command line:
java -jar -Dspring.profiles.active=[yourProfileName] target/[yourJar].jar
I think your problem is likely related to your spring.config.location not ending the path with "/".
Quote the docs
If spring.config.location contains directories (as opposed to files) they should end in / (and will be appended with the names generated from spring.config.name before being loaded).
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-application-property-files
There are two different ways you can add/override spring properties on the command line.
It's important that the -D parameters are before your application.jar otherwise they are not recognized.
java -jar -Dspring.profiles.active=prod application.jar
I had to add this:
bootRun {
String activeProfile = System.properties['spring.profiles.active']
String confLoc = System.properties['spring.config.location']
systemProperty "spring.profiles.active", activeProfile
systemProperty "spring.config.location", "file:$confLoc"
}
And now bootRun picks up the profile and config locations.
Thanks a lot @jst for the pointer.
-Dspring.profiles.active=staging -Dspring.config.location=C:\Config
is not correct.
should be:
--spring.profiles.active=staging --spring.config.location=C:\Config
If you use Gradle:
-Pspring.profiles.active=local