弹簧配置文件激活(非编程)

时间:2015-03-14 12:20:07

标签: java spring

有没有办法以非编程方式激活弹簧配置文件,是否可以决定在运行时使用哪个配置文件?

1 个答案:

答案 0 :(得分:2)

您可以@Autowire Environment类,它具有在运行时检查活动配置文件的方法。这是environment class documentation

对于非程序化配置文件激活,您可以像这样启动您的应用程序:

$ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar

因此spring.profiles.active可以设置个人资料。

相关问题