How the Spring Framework's XML file reads the properties file data

Source: Internet
Author: User

How the Spring Framework's XML file reads the properties file data

First step: In the Spring configuration file

Note: Value can be configured with more than a few properties files

<bean id= "Propertyconfigurer"

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

<property name= "Locations" >

<list>

<value>/db.properties</value>

                     

</list>

</property>

</bean>

Step Two:

Build the Db.properties file under the src directory

User=sa

Password=sa

Driver=com.microsoft.sqlserver.jdbc.sqlserverdriver

Url=jdbc:sqlserver://localhost:1433;databasename=db1

Step Three:

called in Spring's configuration file by means of an El expression

${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>

How the Spring Framework's XML file reads the properties file data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.