zoukankan      html  css  js  c++  java
  • Spring配置从配置文件读取属性值

    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。

  • 相关阅读:
    数据库注意事项
    SQL函数
    2019 SDN阅读作业(2)
    2019 SDN上机第五次作业
    2019 SDN上机第四次作业
    2019 SDN阅读作业
    2019 SDN上机第三次作业
    mysql使用记录
    2019 SDN上机第二次作业
    2019 SDN上机第一次作业
  • 原文地址:https://www.cnblogs.com/zi-yao/p/7561420.html
Copyright © 2011-2022 走看看