spring4.x dbcp,dbcp2连接池基本配置BasicDataSource

https://blog.csdn.net/kingmax54212008/article/details/79525340

 

一、dbcp

spring配置文件

Xml代码   收藏代码
  1.   
  2. <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  3.     <property name="locations">  
  4.         <list>  
  5.             <value>classpath:jdbc.propertiesvalue>  
  6.         list>  
  7.     property>  
  8. bean>  
  9.   
  10.   
  11. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  
  12.     destroy-method="close">  
  13.     <property name="driverClassName" value="${driverClassName}" />  
  14.     <property name="url" value="${url}" />  
  15.     <property name="username" value="${username}" />  
  16.     <property name="password" value="${password}" />  
  17.       
  18.     <property name="initialSize" value="3" />  
  19.       
  20.     <property name="minIdle" value="3" />  
  21.       
  22.     <property name="maxIdle" value="5" />  
  23.       
  24.     <property name="maxActive" value="15" />  
  25. bean>  

 jdbc.properties

Java代码   收藏代码
  1. #dbcp  
  2. driverClassName=com.mysql.jdbc.Driver  
  3. url=jdbc:mysql://localhost:3306/uplatEui?useUnicode=true&characterEncoding=utf-8  
  4. username=root  
  5. password=password  

maven pom.xml

Xml代码   收藏代码
  1. <dependency>  
  2.     <groupId>commons-dbcpgroupId>  
  3.     <artifactId>commons-dbcpartifactId>  
  4.     <version>1.4version>  
  5. dependency>  

 

二、dbcp2

dbcp2需要jdk1.7,否则会报错:Unsupported major.minor version 51.0

maxActive改为了maxTotal

spring配置文件

Xml代码   收藏代码
  1.   
  2. <bean id="dataSource2" class="org.apache.commons.dbcp2.BasicDataSource"  
  3.     destroy-method="close">  
  4.     <property name="driverClassName" value="${driverClassName}" />  
  5.     <property name="url" value="${url}" />  
  6.     <property name="username" value="${username}" />  
  7.     <property name="password" value="${password}" />  
  8.       
  9.     <property name="initialSize" value="3" />  
  10.       
  11.     <property name="minIdle" value="3" />  
  12.       
  13.     <property name="maxIdle" value="5" />  
  14.       
  15.     <property name="maxTotal" value="15" />  
  16. bean>  

maven pom.xml

Xml代码   收藏代码
  1. <dependency>  
  2.     <groupId>org.apache.commonsgroupId>  
  3.     <artifactId>commons-dbcp2artifactId>  
  4.     <version>2.1.1version>  
  5. dependency>  

 

spring4.x c3p0连接池基本配置ComboPooledDataSource
http://happyqing.iteye.com/blog/2303239

 

spring4.x jdbcTemplate配置,事务配置
http://happyqing.iteye.com/blog/2303240

你可能感兴趣的:(spring)