覆盖spring xml中的属性和系统属性

时间:2013-02-19 12:20:11

标签: java spring

在我的Spring配置中,我有以下几行:

<context:property-placeholder
   location="/META-INF/spring/global.properties,#{systemProperties['external.propertyFile'] ?: ''}, /WEB-INF/local.properties"
   ignore-resource-not-found="true" />

我的目的是在global.properties中附加一些默认值,这些默认值应该被另一个通过external.propertyFile传入的外部文件覆盖,并且某些属性由local.properties中的应用程序本身保留在本地

从我在日志中看到的内容 - global.propertieslocal.properties被正确处理,但#{systemProperties ... }的替换似乎不起作用。

任何提示是如何修复或解决它的?

以下是我的应用程序中的相关日志(缩短了一点):

Loading properties file from ServletContext resource [/META-/spring/counter.properties]
Loading properties file from ServletContext resource [/#{systemProperties['external.propertyFile'] ?: ''}]
   WARN support.PropertySourcesPlaceholderConfigurer: Could not load properties from ServletContext resource [/#{systemProperties['external.propertyFile'] ?: ''}]: Could not open ServletContext resource [/#{systemProperties['external.propertyFile'] ?: ''}]
Loading properties file from ServletContext resource [/WEB-INF/local.properties]

只是一句话:

在相同XML配置的其他地方,替换工作正常 - 例如。用:

<util:properties
   id="myProp"
   location="#{systemProperties['my.propertyFile'] ?: '/META-INF/spring/my.properties'}"/>

但这次我需要一种更复杂的方法来处理/合并实际的属性值:(

1 个答案:

答案 0 :(得分:0)

这对我来说很好用

<context:property-placeholder
   location="/META-INF/spring/global.properties,${external.propertyFile},/WEB-INF/local.properties"
   ignore-resource-not-found="true" />
相关问题