zoukankan      html  css  js  c++  java
  • spring 框架的xml文件如何读取properties文件数据

    spring 框架的xml文件如何读取properties文件数据

    第一步:在spring配置文件中

      注意:value可以多配置几个properties文件

    <bean id="propertyConfigurer"

                  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

                  <property name="locations">

                         <list>

                                <value>/db.properties</value>

                               

                         </list>

                  </property>

           </bean>

    第二步:

      在src目录下面建立db.properties文件

    user=sa

    password=sa

    driver=com.microsoft.sqlserver.jdbc.SQLServerDriver

    url=jdbc:sqlserver://localhost:1433;databaseName=DB1

    第三步:

      在spring的配置文件中通过EL表达式的形式调用 

     ${user}

    <?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"

           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

           <bean id="propertyConfigurer"

                  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

                  <property name="locations">

                         <list>

                                <value>/db.properties</value>

                         </list>

                  </property>

           </bean>

           <bean id="datasource"

                  class="org.springframework.jdbc.datasource.DriverManagerDataSource">

                  <property name="driverClassName"

                         value="${driver}">

                  </property>

                  <property name="url"

                         value="${url}">

                  </property>

                  <property name="username" value="${user}"></property>

                  <property name="password" value="${password}"></property>

           </bean>

           <bean id="sessionFactory"

                  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

                  <property name="dataSource">

                         <ref bean="datasource" />

                  </property>

                  <property name="hibernateProperties">

                         <props>

                                <prop key="hibernate.dialect">

                                      org.hibernate.dialect.SQLServerDialect

                                </prop>

                         </props>

                  </property>

                  <property name="mappingResources">

                         <list>

                                <value>entity/Users.hbm.xml</value>

                         </list>

                  </property>

           </bean>

           <bean id="UsersDAO" class="dao.UsersDAO">

                  <property name="sessionFactory">

                         <ref bean="sessionFactory" />

                  </property>

           </bean>

     </beans>

  • 相关阅读:
    react-router JS 控制路由跳转(转载)
    vue 将值存储到vuex 报错问题
    封装GetQueryString()方法来获取URL的value值(转载)
    vue 里面的watch 选项详解
    谷歌地图api 开发 (转载)
    es6 ...展开运算符
    关于localStorage 应用总结
    js 刷新当前页面会弹出提示框怎样将这个提示框去掉
    深入浅析JavaScript的API设计原则(转载)
    jQuery mouseover与mouseenter,mouseout与mouseleave的区别
  • 原文地址:https://www.cnblogs.com/yangyi9343/p/5674004.html
Copyright © 2011-2022 走看看