数据库连接池切换为hikari

This commit is contained in:
2026-06-12 16:58:59 +08:00
parent 56f0e4c509
commit 7313a8fe6f
9 changed files with 77 additions and 32 deletions
+8
View File
@@ -33,6 +33,14 @@
<groupId>org.xujun</groupId>
<artifactId>xtools-app-sys-scheduled</artifactId>
</dependency>
<!--<dependency>-->
<!-- <groupId>org.xujun</groupId>-->
<!-- <artifactId>xtools-boot-db-druid</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.xujun</groupId>
<artifactId>xtools-boot-db-hikari</artifactId>
</dependency>
<dependency>
<groupId>org.xujun</groupId>
<artifactId>xtools-app-sys-log-bus-elasticsearch</artifactId>
@@ -10,32 +10,4 @@ spring:
# 数据库用户名
username: ${DB_USERNAME:root}
# 数据库密码
password: ${DB_PASSWORD:root}
# 数据库类型
type: com.alibaba.druid.pool.DruidDataSource
druid:
# 连接池配置
# 初始化时建立物理连接的个数.初始化发生在显示调用init方法,或者第一次getConnection时
initial-size: 1
# 最小连接池数量
min-idle: 5
# 最大连接池数量
max-active: 30
# 获取连接时最大等待时间,单位毫秒.配置了maxWait之后,缺省启用公平锁,并发效率会有所下降,如果需要可以通过配置useUnfairLock属性为true使用非公平锁
max-wait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time-between-eviction-runs-millis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 300000
# 用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'.如果validationQuery为null,testOnBorrow,testOnReturn,testWhileIdle都不会起作用
validation-query: SELECT 'x'
# 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
test-on-borrow: false
# 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
test-on-return: false
# 建议配置为true,不影响性能,并且保证安全性.申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效
test-while-idle: true
# 是否缓存preparedStatement,也就是PSCache.PSCache对支持游标的数据库性能提升巨大,比如说oracle.在mysql下建议关闭
pool-prepared-statements: false
# 要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true.在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100
max-pool-prepared-statement-per-connection-size: 10
password: ${DB_PASSWORD:root}
@@ -1,7 +1,35 @@
# 数据库配置
spring:
datasource:
# 数据库类型
type: com.alibaba.druid.pool.DruidDataSource
druid:
# 连接池配置
# 初始化时建立物理连接的个数.初始化发生在显示调用init方法,或者第一次getConnection时
initial-size: 1
# 最小连接池数量
min-idle: 5
# 最大连接池数量
max-active: 30
# 获取连接时最大等待时间,单位毫秒.配置了maxWait之后,缺省启用公平锁,并发效率会有所下降,如果需要可以通过配置useUnfairLock属性为true使用非公平锁
max-wait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time-between-eviction-runs-millis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 300000
# 用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'.如果validationQuery为null,testOnBorrow,testOnReturn,testWhileIdle都不会起作用
validation-query: SELECT 'x'
# 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
test-on-borrow: false
# 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
test-on-return: false
# 建议配置为true,不影响性能,并且保证安全性.申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效
test-while-idle: true
# 是否缓存preparedStatement,也就是PSCache.PSCache对支持游标的数据库性能提升巨大,比如说oracle.在mysql下建议关闭
pool-prepared-statements: false
# 要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true.在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100
max-pool-prepared-statement-per-connection-size: 10
# 使用的过滤器类型
filters: stat,wall,config
@@ -0,0 +1,18 @@
# 数据库配置
spring:
datasource:
# 数据库类型
type: com.zaxxer.hikari.HikariDataSource
hikari:
# 连接超时时间
connection-timeout: 30000
# 获取连接时最大等待时间
idle-timeout: 60000
# 连接最长生命周期
max-lifetime: 1800000
# 最小连接数
minimum-idle: 5
# 最大连接数
maximum-pool-size: 30
# 测试连接
connection-test-query: SELECT 1
@@ -10,7 +10,8 @@ spring:
# Boot
- boot-base
- boot-db
- boot-druid
# - boot-druid
- boot-hikari
- boot-elasticsearch
- boot-knife4j
- boot-log