一、HiKariCP简述
HikariCP是由日本程序员开源的一个数据库连接池组件,代码非常轻量,并且速度非常的快。
二、如何使用HiKariCP
本次采用Mybatis_plus结合HiKariCP一起使用
1、整合Mybatis_plus见我的博客
Springboot 集成Mybatis_Plus_编码语者 Dragon Wu的博客-CSDN博客
2、配置文件如:
server:
port: 8088
tomcat:
uri-encoding: UTF-8
jetty:
max-http-form-post-size: 80KB
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource # 数据源类型为HiKariCP
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/admin?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8
username: root
password: root
hikari:
connection-timeout: 30000 # 等待连接池配置连接的最大时长(毫秒),超过这个时长还没连接则会发生SQLException,默认是30000
minimum-idle: 5 #最小连接数
maximum-pool-size: 20 # 最大连接数
auto-commit: true #自动提交
idle-timeout: 600000 # 连接超时的最大时长(毫秒),超时则被释放(retired),默认:10分钟
pool-name: DateSourceHikariCP #连接池名字
max-lifetime: 1800000 # 连接的生命时长(毫秒),超时而且没被使用则被释放(retired),默认30分钟 1800000ms
connection-test-query: SELECT 1
mybatis-plus:
configuration:
map-underscore-to-camel-case: true
# 该配置就是将带有下划线的表字段映射为驼峰格式的实体类属性
global-config:
db-config:
table-prefix: #表前缀
# id-type: auto #设置id自增