我正在尝试使用我正在部署的机器上的本地属性文件来覆盖我的 war 文件中找到的默认值。
<context:property-placeholder
location="classpath*:*.properties, file:/var/myfolder/local.properties"
ignore-resource-not-found="true"
ignore-unresolvable="true" />
我发现这可以通过提供一个文件作为第二个位置(逗号分隔)来实现。不幸的是,它似乎没有覆盖属性。
我尝试过使用属性定义 bean 并设置位置,但这也不起作用。
最佳答案
一种方法是将它们分成两部分并使用顺序
<context:property-placeholder
location="classpath*:*.properties"
ignore-resource-not-found="true"
ignore-unresolvable="true"
order ="0" />
<context:property-placeholder
location="file:/var/myfolder/local.properties"
ignore-resource-not-found="true"
ignore-unresolvable="true"
order="-1"/>
最低顺序优先
关于spring - 使用本地属性文件覆盖 Spring 3.1 中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11645360/