spring中配置文件占位符的使用

1.类

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="propertyConfigurer"  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <!-- 
        使用location属性定义单个配置文件
        <property name="location">
            <value>classpath:/com/zsw/config/jdbc.properties</value>
        </property>
         -->
  
  <!-- 使用locations属性定义多个配置文件 -->
  <property name="locations">
     <list>
        <value>classpath:/com/zsw/config/jdbc.properties</value>
     </list>
  </property> 
    </bean>
    <bean id="dataSource"  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="url">
            <value>${database.url}</value>
        </property>
        <property name="driverClassName">
            <value>${database.driver}</value>
        </property>
        <property name="username">
            <value>${database.user}</value>
        </property>
        <property name="password">
            <value>${database.password}</value>
        </property>
    </bean>
</beans>

2.

<context:property-placeholder location="http://prop_server/${env_path}/ibs/s-permission.properties" />

<import resource="application-dao.xml" />

<import resource="application-app.xml" />

<import resource="application-dubbo.xml" />

猜你喜欢

转载自avords.iteye.com/blog/2217302