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>

  • 相关阅读:
    部署 AppGlobalResources 到 SharePoint 2010
    还原一个已删除的网站集
    使用仪表板设计器配置级联筛选器 (SharePoint Server 2010 SP1)
    File or arguments not valid for site template
    Pex and Moles Documentation
    Content Query Webpart匿名访问
    Running Moles using NUnit Console from Visual Studio
    Calling a WCF Service using jQuery in SharePoint the correct way
    Updating Content Types and Site Columns That Were Deployed as a Feature
    asp.net中判断传过来的字符串不为空的代码
  • 原文地址:https://www.cnblogs.com/yangyi9343/p/5674004.html
Copyright © 2011-2022 走看看