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

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

原文链接:http://www.cnblogs.com/yangyi9343/p/5674004.html

第一步:在spring配置文件中

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

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

              

                     

                            /db.properties

                           

                     

              

       

第二步:

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

user=sa

password=sa

driver=com.microsoft.sqlserver.jdbc.SQLServerDriver

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

第三步:

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

 ${user}

       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">

 

       

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

              

                     

                            /db.properties

                     

              

       

 

       

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

              

                     value="${driver}">

              

              

                     value="${url}">

              

              

              

       

       

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

              

                     

              

              

                     

                            

                                  org.hibernate.dialect.SQLServerDialect

                            

                     

              

              

                     

                            entity/Users.hbm.xml

                     

              

       

       

              

                     

              

       

 

你可能感兴趣的:(框架)