Setting active profile and config location from command line in spring boot
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.
Setting the default active profile in Spring-boot
What you are doing here is setting the default default profile (the profile that is used on any bean if you don't specify the @Profile
annotation) to be production
.
What you actually need to do is set the default active profile, which is done like this:
spring.profiles.active=production
How do I activate a Spring Boot profile when running from IntelliJ?
I added -Dspring.profiles.active=test
to VM Options and then re-ran that configuration. It worked perfectly.
This can be set by
- Choosing
Run | Edit Configurations...
- Go to the
Configuration
tab - Expand the
Environment
section to revealVM options
Configure active profile in SpringBoot via Maven
The Maven profile and the Spring profile are two completely different things. Your pom.xml defines spring.profiles.active
variable which is available in the build process, but not at runtime. That is why only the default profile is activated.
How to bind Maven profile with Spring?
You need to pass the build variable to your application so that it is available when it is started.
Define a placeholder in your
application.properties
:spring.profiles.active=@spring.profiles.active@
The
@spring.profiles.active@
variable must match the declared property from the Maven profile.Enable resource filtering in you pom.xml:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
…
</build>When the build is executed, all files in the
src/main/resources
directory will be processed by Maven and the placeholder in yourapplication.properties
will be replaced with the variable you defined in your Maven profile.
For more details you can go to my post where I described this use case.
Related Topics
How to Match "Any Character" in Regular Expression
How to Change the Size of the Font of a Jlabel to Take the Maximum Size
How to Parse a JSON String to an Array Using Jackson
What Is the "Default" Implementation of Method Defined in an Interface
Can't a Swing Component Be Added to Multiple Containers
How to Format Localdate to String
Firestore Query Documents Startswith a String
How to Shuffle Characters in a String Without Using Collections.Shuffle(...)
Preparedstatement with Statement.Return_Generated_Keys
Why Is "Final" Not Allowed in Java 8 Interface Methods
Java 7 String - Substring Complexity
Improvednamingstrategy No Longer Working in Hibernate 5
Are There Inline Functions in Java