javaspringspring-profiles

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 currently active and default profiles from Spring?


Solution

  • You can autowire the Environment

    @Autowired
    Environment env;
    

    Environment offers: