这是我的 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 bean 配置文件实际上与部署/测试应用程序的环境相匹配。
我的位置属性仍然被解析为“/properties/test/some.properties”。这当然是因为 spring.profiles.active 在这种情况下似乎没有得到解决。
我怎样才能获得正确的属性?
这是因为活跃的配置文件may由系统属性激活(但如果@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"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)