hikari数据库连接池
先上依赖
HikariCP现在已经是spring-boot-starter-jdbc中自带的默认连接池,如果引入了spring-boot-starter-jdbc就不需要引入了
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
github地址:https://github.com/brettwooldridge/HikariCP
yml配置
spring:
datasource:
#url: jdbc:mysql://xxx.xxx.xxx.xxx:3306/sell?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&rewriteBatchedStatements=true
#username: root
#password: 10086
#driver-class-name: com.mysql.cj.jdbc.Driver
#type: com.zaxxer.hikari.HikariDataSource
## Hikari 连接池配置 ------ 详细配置请访问:https://github.com/brettwooldridge/HikariCP
## 最小空闲连接数量
#hikari:
# 空闲连接的最大数量
#minimum-idle: 5
# 空闲连接存活最大时间,默认600000(10分钟)
#idle-timeout: 180000
# 连接池的最大连接数量,超过最大空闲连接的数量之后,经过上面的idle-timeout后连接数量会恢复到minimum-idle
#maximum-pool-size: 10
#connection 事务自动提交,默认就是true
#auto-commit: true
# 连接池名称
#pool-name: myHikaricp
# 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟,为了防止连接雪崩,通常设置的比数据库的闲置时间小几秒
#max-lifetime: 1800000
# 连接mysql最大超时时间
#connection-timeout: 30000
#connection-test-query: select 1
# 在test 连接是否可用的时候的最大时间,默认500ms,最少 250ms
#validation-timeout: 500
url: jdbc:mysql://xxx.xxx.xxx.xxx:3306/sell?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&rewriteBatchedStatements=true
username: root
password: 10086
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.zaxxer.hikari.HikariDataSource
hikari:
minimum-idle: 5
idle-timeout: 180000
maximum-pool-size: 10
auto-commit: true
pool-name: myHikaricp
max-lifetime: 180000
connection-timeout: 30000
connection-test-query: select 1
validation-timeout: 500