Reputation: 1029
I have created Profiles in Java class like this,
@Profile(value = "cache")
public class MapCache {
....
}
These profiles are not getting activated when spring.profiles.active used, but if i use spring.profiles.include profiles are working fine.
I would like activate profiles through properties which are added in application.properties
Note: application is running in independent jetty instance.
Any tip would be great on this.
Upvotes: 4
Views: 45910
Reputation: 109
Hint: for IntellyJ fans
Do not forget to select "Add VM Options" in "Modify Options" dropdown of Edit Configurations dialog and then enter
-Dspring.profiles.active=...
Upvotes: 3
Reputation: 737
I encountered a similar issue where SpringBoot wasn't activating the profiles set in the spring.profiles.active application property.
The issue was the result of the code base using a non standard name and location for the application property file (not my doing). Once I specified the location via the command line arg- --spring.config.location=/non/standard/location/acme.properties
- the profile was activated.
Upvotes: 0
Reputation: 651
you can also try to run the application and pass them as command line args
java -jar -Dspring.profiles.active={your_profile_name} application.jar
or if you run the app via maven:
mvn spring-boot:run -Dspring-boot.run.profiles={your_profile_name}
Here is an nice example I found on the internet with all the ways you can set the spring profile, it should help : https://www.baeldung.com/spring-profiles
Upvotes: 5
Reputation: 2884
To activate a profile via annotations you need @ActiveProfile("profileName")
. The @Profile
annotation is used to label an object as being a member of the profile.
Upvotes: 5