Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | About

2.12. Connection and Statement Pooling

注意:下面的实例仅限 Spring boot 1.3.0.RELEASE

2.12.1. org.apache.tomcat.jdbc.pool.DataSource

默认连接池,可以忽略配置

				spring.datasource.type = org.apache.tomcat.jdbc.pool.DataSource
			

2.12.2. druid

pom.xml

			
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.24</version>
		</dependency>
			
			

application.properties

			
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
spring.datasource.timeBetweenEvictionRunsMillis=60000 
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false 
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.filters=stat,wall,log4j
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
#spring.datasource.useGlobalDataSourceStat=true		

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://192.168.6.1:3306/test
spring.datasource.username=inf
spring.datasource.password=inf
spring.jpa.database=MYSQL
			
			

2.12.3. c3p0 - JDBC3 Connection and Statement Pooling

pom.xml

			
		<dependency>
		    <groupId>org.hibernate</groupId>
		    <artifactId>hibernate-c3p0</artifactId>
		    <version>4.3.6.Final</version>
		</dependency>
		<dependency>
		    <groupId>c3p0</groupId>
		    <artifactId>c3p0</artifactId>
		    <version>0.9.1.2</version>
		</dependency>
			
			

application.properties

			
spring.datasource.type=com.mchange.v2.c3p0.ComboPooledDataSource
			
			

2.12.4. dbcp2

			
spring.datasource.type = org.apache.commons.dbcp2.BasicDataSource			
			
			

2.12.5. bonecp

			
spring.datasource.type = com.jolbox.bonecp.BoneCPDataSource		
			
			

2.12.6. dbcp2

			
spring.datasource.type = org.apache.commons.dbcp2.BasicDataSource