Spring introduces property configuration through the. Properties file

Source: Internet
Author: User

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&amp;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&amp;)。




Spring introduces property configuration through the. Properties file

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.