I have 5 environments:
- local (my development machine)
- dev
- qc
- uat
- live
- staging
I want different application properties to be u
I ended up adding the following to my build.gradle:
bootRun {
environment SPRING_PROFILES_ACTIVE: environment.SPRING_PROFILES_ACTIVE ?: "local"
}
test {
environment SPRING_PROFILES_ACTIVE: environment.SPRING_PROFILES_ACTIVE ?: "test"
}
So now when running bootRun from IntelliJ, it defaults to the "local" profile.
On our other environments, we will simply set the 'SPRING_PROFILES_ACTIVE' environment variable in Tomcat.
I got this from a comment found here: https://github.com/spring-projects/spring-boot/pull/592
I added -Dspring.profiles.active=test
to VM Options and then re-ran that configuration. It worked perfectly.
This can be set by
Run | Edit Configurations...
Configuration
tab Environment
section to reveal VM options
Try add this command in your build.gradle
So for running configure that shape:
A probable cause could be that you do not pass the command line parameters into the applications main method. I made the same mistake some weeks ago.
public static final void main(String... args) {
SpringApplication.run(Application.class, args);
}
Try this. Edit your build.gradle file as followed.
ext { profile = project.hasProperty('profile') ? project['profile'] : 'local' }
So for resuming...
If you have the IntelliJ Ultimate the correct answer is the one provided by Daniel Bubenheim
But if you don't, create in Run->Edit Configurations and in Configuration tab add the next Environment variable:
SPRING_PROFILES_ACTIVE=profilename
And to execute the jar do:
java -jar -Dspring.profiles.active=profilename XXX.jar