码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-01-23 19:59:27      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

spring将properties文件读取后在配置文件中直接将对象的配置信息填充到bean中的变量里。

原本使用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" />

注意:spring容器中最多只能定义一个context:property-placeholder。

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

标签:

原文地址:http://www.cnblogs.com/brolanda/p/4244801.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!