这里说的是ali的开源项目druid。
druid连接池是很常用的一种连接池,效果挺不错,而且还是ali的亲儿子。

pom.xml中添加

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid-version}</version>
</dependency>

一些配置

使用链接池还是很有用的。
常用配置如下:

spring:
datasource:
url: jdbc:mysql://localhost:3306/helowin?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
username: root
password: 666
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
max-idle: 10
max-wait: 1000
min-idle: 5
initial-size: 5
output.ansi.enabled: always
# 配置druid
druid:
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM t_user
testWhileIdle: true
testOnBorrow: true
testOnReturn: false
# 打开PSCache,并且指定每个连接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
filters: stat,wall,log4j
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 合并多个DruidDataSource的监控数据
# useGlobalDataSourceStat: true

其他

文档

github druid中文文档:
​​​https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98​