使用本地属性文件覆盖Spring 3.1中的属性

时间:2012-07-25 08:11:05

标签: spring deployment properties

我正在尝试使用我正在部署的框上的本地属性文件覆盖我的war文件中找到的默认值。

<context:property-placeholder
  location="classpath*:*.properties, file:/var/myfolder/local.properties"
  ignore-resource-not-found="true"
  ignore-unresolvable="true" />

我已经看到这可以通过提供一个文件作为第二个位置(以逗号分隔)来实现。不幸的是,它似乎没有覆盖属性。

我尝试使用属性定义bean并设置位置,但这也不起作用。

2 个答案:

答案 0 :(得分:11)

一种方法是将它们分成两个并使用顺序

<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"/>

最低订单优先

答案 1 :(得分:2)

发现问题。由于某种原因,系统中有2个应用程序上下文。我需要调查是否有理由这样做。一旦我将属性文件添加到其他应用程序上下文,它就会起作用。

感谢您的帮助!

相关问题