How do you get current active/default Environment profile programmatically in Spring?

Bobo picture Bobo · Feb 13, 2012 · Viewed 152k times · Source

I need to code different logic based on different current Environment profile. How can you get the current active and default profiles from Spring?

Answer

aweigold picture aweigold · Feb 13, 2012

You can autowire the Environment

@Autowired
Environment env;

Environment offers: