繁体   English   中英

在Spring XML中覆盖属性和系统属性

[英]Override properties and system properties in spring xml

在我的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'}"/>

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

这对我来说很好

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM