分享

使用<context:property-placeholder>标签导入多个properties文件

 jasonbetter 2018-03-20


原创 2017年12月20日 10:10:36

Spring中的xml中使用<context:property-placeholderlocation>标签导入配置文件时,想要导入多个properties配置文件,如下:

<context:property-placeholderlocation="classpath:db.properties " />

<context:property-placeholderlocation="classpath:zxg.properties " />


结果发现不行,第二个配置文件始终读取不到,后来发现<context:property-placeholder>标签在Spring配置文件中只能存在一份!!!Spring容器是采用反射扫描的发现机制,通过标签的命名空间实例化实例,当Spring探测到容器中有一个org.springframework.beans.factory.config.PropertyPlaceholderCVonfigurerBean就会停止对剩余PropertyPlaceholderConfigurer的扫描,即只能存在一个实例。

[html] view plain copy
  1. <context:property-placeholder     
  2.        location=""    
  3.        file-encoding=""    
  4.        ignore-resource-not-found=""   
  5.        ignore-unresolvable=""    
  6.        properties-ref=""    
  7.        local-override=""    
  8.        system-properties-mode=""   
  9.        order=""    
  10. />  

那如果有多个配置文件怎么办呢?那就多个文件之间以“,”分隔,如下:

<context:property-placeholderlocation="classpath:db.properties,classpath:monitor.properties" />


值得注意的是:多个配置文件将依次加载,如果后一个文件中有和前面某一个文件中属性名是相同的,最终取的值是后加载的值。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多