Bobo Bobo -4 years ago 201
Java Question

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

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 Source

You can autowire the Environment

@Autowired
Environment env;

Environment offers String[] getActiveProfiles(), String[] getDefaultProfiles(), and boolean acceptsProfiles(String... profiles)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download