Sunil Rk
Sunil Rk

Reputation: 1029

spring.profiles.active is not working in springboot application

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

Answers (4)

ZoltanB
ZoltanB

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

JohnC
JohnC

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

Opri
Opri

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

Rob Evans
Rob Evans

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

Related Questions