Java 如何使用 Spring boot 以编程方式确定当前活动配置文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28392231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to determine programmatically the current active profile using Spring boot
提问by rayman
Is there a way programmatically to get the current active profile within my bean?
有没有办法以编程方式在我的 bean 中获取当前的活动配置文件?
采纳答案by Artem Bilan
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.
无论您的应用程序是 Boot 还是原始 Spring,这都无关紧要。有足够的注入org.springframework.core.env.Environment
到你的 bean 中。
@Autowired
private Environment environment;
....
this.environment.getActiveProfiles();