如何使用Spring Boot以编程方式确定当前活动配置文件 [英] How to determine programmatically the current active profile using Spring boot
本文介绍了如何使用Spring Boot以编程方式确定当前活动配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过编程方式在bean中获取当前的活动配置文件?
Is there a way programmatically to get the current active profile within my bean?
推荐答案
您的应用程序Boot还是原始Spring都没有关系.将org.springframework.core.env.Environment
注入到您的bean中就足够了.
It doesn't matter is your app Boot or just raw Spring. There is just enough to inject org.springframework.core.env.Environment
to your bean.
@Autowired
private Environment environment;
....
this.environment.getActiveProfiles();
这篇关于如何使用Spring Boot以编程方式确定当前活动配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文