如何在Spring中以编程方式获取当前活动/默认环境配置文件?

如何在Spring中以编程方式获取当前活动/默认环境配置文件?

问题描述:

我需要根据不同的当前环境配置文件编写不同的逻辑。如何从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?

您可以自动装配环境

@Autowired
Environment env;

环境优惠 String [] getActiveProfiles() String [] getDefaultProfiles() boolean acceptsProfiles(String ... profiles)