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.

2 Answers

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.

4

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 :

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like