Java – How to get current active/default Environment profile programmatically in Spring

javaspringspring-profiles

I need to code different logic based on different current Environment profile.

How can you get the currently active and default profiles from Spring?

Best Answer

You can autowire the Environment

@Autowired
Environment env;

Environment offers: