0

Is there a way to activate a spring profile non-programmatically and is it possible to decide which profile is used at runtime?

Cœur
  • 37,241
  • 25
  • 195
  • 267
ishan3243
  • 1,870
  • 4
  • 30
  • 49
  • 1
    Check this question:http://stackoverflow.com/questions/15814497/setting-spring-profile-variable – John Mar 14 '15 at 12:46

1 Answers1

2

You can @Autowire Environment class which has methods to check active profiles at runtime. Here is environment class documentation.

As for non-programatic profile activation you can start your app like this:

$ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar

So spring.profiles.active is there to set profile.

Nenad Bozic
  • 3,724
  • 19
  • 45
  • is it possible to set the spring.profiles.active property using Ant build file? – ishan3243 Mar 15 '15 at 11:51
  • Maven can so I suppose that ant can as well but haven't used it in ages. In maven you can add `-Dspring.profiles.active=devel` to maven execution plugin – Nenad Bozic Mar 15 '15 at 15:23