【问题标题】:spring - <context:property-placeholder> load multiple properties but ignore missing onesspring - <context:property-placeholder> 加载多个属性但忽略丢失的属性
【发布时间】:2016-06-21 10:42:14
【问题描述】:

我在 applicationContext.xml 中使用了以下配置

<context:property-placeholder location="classpath:system.properties,file:/data/conf/system.properties,file:/data/conf/1033.properties" ignore-unresolvable="true" />

加载一些占位符:

  1. 使用classpath:system.properties中定义的这些属性;
  2. 如果/data/conf/system.properties 中存在文件或属性,请使用它们而不是上面的;
  3. 如果/data/conf/1033.properties 中存在文件或属性,请使用它们而不是上面的。

如果/data/conf/system.properties/data/conf/1033.properties 都存在,现在Spring 可以正常启动,但如果它们中的任何一个都不存在,它将抛出rg.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: ...

如何告诉弹簧加载这些属性,但忽略缺失的。

【问题讨论】:

    标签: java spring properties-file property-placeholder


    【解决方案1】:

    您必须添加ignore-resource-not-found="true"

    <context:property-placeholder location="classpath:system.properties,file:/data/conf/system.properties,file:/data/conf/1033.properties" 
       ignore-unresolvable="true"  
       ignore-resource-not-found="true"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-01
      • 1970-01-01
      • 2012-11-23
      • 1970-01-01
      • 2012-09-28
      • 2011-11-24
      • 1970-01-01
      • 2015-10-14
      相关资源
      最近更新 更多