spring配置:context:property-placeholder 讀取配置文件信息 在配置文件中使用el表達式填充值

spring將properties文件讀取後在配置文件中直接將對象的配置信息填充到bean中的變量裏。spring

本來使用PropertyPlaceholderConfigurer類進行文件信息配置。PropertyPlaceholderConfigurer實現了BeanFactoryPostProcessor接口,可以對<bean/>中的屬性值進行外在化管理。
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
    <list>
      <value>userinfo.properties</value>
    </list>
  </property>
</bean>
<bean name="userInfo" class="test.UserInfo">
  <property name="username" value="${db.username}"/>
  <property name="password" value="${db.password}"/>
</bean>

如今,直接使用
<context:property-placeholder location="classpath*:resources/*.properties" />spa

注意:spring容器中最多隻能定義一個context:property-placeholder。對象

相關文章
相關標籤/搜索