Spring讀取Properties配置文件

spring讀取properties的方法 html

首先在配置文件中配置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}"/>  web

相關文章
相關標籤/搜索