您的位置:首页 > 编程语言 > Java开发

Spring中加载多个Properties配置文件

2015-03-20 11:05 435 查看
单个配置:

<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: