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

前端 未结 6 928
梦毁少年i
梦毁少年i 2020-11-29 19:17

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

6条回答
  •  误落风尘
    2020-11-29 20:17

    You can autowire the Environment

    @Autowired
    Environment env;
    

    Environment offers:

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

提交回复
热议问题