qinyubin

导航

Spring中加载多个Properties配置文件

单个配置:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location">
    <value>classpath:jdbc.properties</value>
  </property>
</bean>

多个配置:

<!-- 将多个配置文件读取到容器中,交给Spring管理 --> 

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
    <list>
      <!-- 这里支持多种寻址方式:classpath和file -->
      <value>classpath:/opt/demo/config/demo-db.properties</value>
       <!-- 推荐使用file的方式引入,这样可以将配置和代码分离 -->
      <value>file:/opt/demo/config/demo-mq.properties</value>
      <value>file:/opt/demo/config/demo-remote.properties</value>
    </list>
  </property>
</bean>

posted on 2015-03-20 11:05  qinyubin  阅读(522)  评论(0编辑  收藏  举报