散文吧>Netkiller>Spring boot · 链接池配置

Spring boot · 链接池配置

2016-10-31 17:40 | Netkiller

Spring boot · 链接池配置

本文节选自《Netkiller Java 手札》

http://www.netkiller.cn/java/spring/boot/index.html

10.16. Connection and Statement Pooling

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

10.16.1. org.apache.tomcat.jdbc.pool.DataSource

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

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

10.16.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			
			

10.16.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			
			

10.16.4. dbcp2

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

10.16.5. bonecp

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

10.16.6. dbcp2

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

作者相关文章:

Spring Tool Suite

Spring boot with Spring security

Spring RestFul and RestTemplate

Spring boot with Velocity template

Spring boot with Email

Spring boot with Oracle

Spring boot with MySQL 实例参考

Spring Boot · Mongo Repository

Spring Boot MongoDB 实例

Spring Boot 快速开始


关注作者公众号,每日**原创文章。如果已有什么建议,请给我留言。