这是我的applicationContext定义的一部分,用于检索一些属性。
<!-- get some properties -->
<context:property-placeholder
ignore-resource-not-found="false" ignore-unresolvable="false"
location="classpath:/properties/${spring.profiles.active:test}/some.properties"/>如您所见,我让spring.profiles.active决定将读取哪些属性。我的测试注释如下:
@ActiveProfile("integration")您猜对了,我的spring配置文件实际上与部署/测试应用程序的环境匹配。我的location属性仍然被解析为“/properties/test/ome.properties”。当然,这是因为在这种情况下,spring.profiles.active似乎没有得到解决。
我如何才能获得正确的属性?
发布于 2013-03-05 17:05:25
这是因为active profiles 可以通过系统属性激活(但如果是@ActiveProfiles,则以另一种方式工作)。
就像这样:
<beans profile="dev,prod,qa">
<context:property-placeholder location="classpath:some.properties" ignore-unresolvable="true"/>
</beans>
<beans profile="test">
<context:property-placeholder location="classpath:some-test.properties" ignore-unresolvable="true"/>
</beans>此外,您还可以尝试将location="classpath:/properties/${spring.profiles.active:test}/some.properties"更改为location="classpath:/properties/${spring.profiles.active}/some.properties"。
发布于 2013-03-06 11:12:37
见票证:https://jira.springsource.org/browse/SPR-8982#comment-88498
有人已经提出了这样的要求:
通过"-Dspring.profiles.active“或其他systemProperty从命令行重写运行时测试指定的@ActiveProfile的选项
我的意见是:
或者它应该设置属性spring.profiles.active。
https://stackoverflow.com/questions/15228441
复制相似问题