【发布时间】:2015-06-04 09:45:03
【问题描述】:
我正在尝试在我的 Spring 上下文中加载一个属性文件(位于战争之外),其路径来自系统属性。
如果该系统属性不存在或找不到路径,我想回退到包含在我的 .war 中的默认属性文件。
这是我的 applicationContext.xml 的特定部分
<context:property-placeholder ignore-resource-not-found="true" ignore-unresolvable="true" location="file:${config.dir}/config/server.properties"/>
<context:property-placeholder ignore-resource-not-found="false" location="classpath:config/server.properties"/>
问题是当在系统属性中找不到 config.dir 时,会抛出一个异常,说明解析器找不到该属性。
即使它会解决,我很确定第二行会使得在参数中给出的文件中加载的属性被默认文件中的属性替换,这与我的相反想做。
我正在使用 Spring 4.x,仅配置 xml。
有没有可能做我想做的事? 我知道基于 Java 的配置的 @Conditional,但我只能使用 xml 方式来响应项目的标准。
【问题讨论】:
标签: spring