Spring本地和系统属性

时间:2013-12-07 10:57:01

标签: java spring properties

只有在未设置系统属性(来自操作系统)的情况下,才可以在spring中使用本地属性(在applicationContext.xml中声明)。现在,本地属性覆盖了所有系统属性。我希望系统属性的优先级更多地是本地的。

我从操作系统中设置的文件和系统属性中导入本地属性:

<context:property-placeholder location="classpath:localhost.properties" />

我无法实现自定义PropertyPlaceholders。

3 个答案:

答案 0 :(得分:1)

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

<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 :(得分:1)

这不是你想要的(来自PropertyPlaceholderConfigurer api)吗?

public void setSystemPropertiesMode(int systemPropertiesMode)

Set how to check system properties: as fallback, as override, or never. For example, will resolve ${user.dir} to the "user.dir" system property.
The default is "fallback": If not being able to resolve a placeholder with the specified properties, a system property will be tried. "override" will check for a system property first, before trying the specified properties. "never" will not check system properties at all.

你应该添加这个

<property name="searchSystemEnvironment" value="true"/>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>

到你的占位符配置器

答案 2 :(得分:0)

所以如果我做对了你就不要把它们放在当地? 的更新 你也可以在systemPropertiesMode元素中使用system_properties_mode_override i blv