1. Introduction of the context namespace in spring beans
<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance " <span style=" color: #ff0000; " > xmlns:context= "http://www.springframework.org/schema/context" </span> xsi:schemalocation= "http +/ Www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd <span style= "color: #ff0000;" >http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-2.5.xsd</span> ">
2. Original Bean configuration file
<bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" > < Property Name= "Driverclassname" value= "Org.git.mm.mysql.Driver"/> <property name= "url" value= "Jdbc:mysql ://localhost:3306/spring?useunicode=true&characterencoding=utf-8 "/> <property name=" username " value= "root"/> <property name= "password" value= "11111111"/> <!--initial value when connection pooling starts-- < Property Name= "InitialSize" value= "1"/> <!--connection Pool max-- <property name= "maxactive" value= " "/> <!--maximum idle value, when a peak time has elapsed, the connection pool can slowly release the connection that has not been used, and has been reduced to msxidle until--><property name=" Maxidle "value=" 2 "/><!--minimum idle value, when the number of idle connections is less than the threshold, the connection pool will pre-request some connections, so as not to apply--><property name=" Minidle "value=" 1 "/> </ Bean>
3.vim test.properties Add properties file to src directory
driverclassname=org.gjt.mm.mysql.driverurl=jdbc:mysql://localhost:3306/spring?useunicode=true& Characterencoding=utf-8username=rootpassword=11111111initialsize=1maxactive=500maxidle=2minidle=1
4. Modify the original bean configuration file to
<span style= "White-space:pre" ></span><context:property-placeholder location= "jdbc.properties"/ > <bean id= "dataSource" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" > < Property Name= "Driverclassname" value= "${driverclassname}"/> <property name= "url" value= "${url}"/> <property name= "username" value= "${username}"/> <property name= "password" value= "${password}"/> &L t;! -- initial value when connection pooling starts --> <property name= "initialsize" value= "${initialsize}"/> <!- -Maximum Connection pool value--<property name= "maxactive" value= "${maxactive}" ></property> <!-- Max idle value, when After a peak time, the connection pool can slowly release the connection that has not been used, until Msxidle --><property name= "Maxidle" value= "${maxidle}"/> <!-- Minimum idle value, when the number of idle connections is less than the threshold, the connection pool will pre-apply for some connections, lest the flood peak when the arrival of --><property name= "Minidle" value= "${ Minidle} "/> </bean>
Description: Through the property placeholder, the property profile is introduced into value by ${x}, and X is the left half of the equal sign in the configuration file. (In the configuration file,&will automatically be converted to when read&)。
Spring introduces property configuration through the. Properties file