Fork me on GitHub

spring读取properties的方法

首先在配置文件中配置PropertyPlaceholderConfigurer 

单个配置文件: 
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  <property name="locations" value="classpath:com/foo/jdbc.properties"/>  
</bean>  
多个配置文件: 
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
  <property name="locations"> 
    <list>            
        <value>classpath:jdbc.properties</value> 
        <value>classpath:config.properties</value> 
   </list>

</property> 
</bean> 

然后在需要的地方直接以下方式引用: 
<property name="url" value="${jdbc.url}"/>  

posted @ 2013-10-24 17:34  symbolJerry²º¹³  阅读(508)  评论(0编辑  收藏  举报