HikariCP 凭借体积小,性能高,稳定可靠的特性,已经成为目前体验最好的数据库连接池。
HikariCP的优点不再论证,springboot2 默认使用的连接池就是 HikariCP。
新建一个 springboot2 项目,配置好 jdbc 和 jpa 后,启动项目。可以看到如下日志:
说明 springboot2 默认使用 HikariCP 来提高性能。可以通过修改 application.yml 文件来配置 HikariCP 参数:
spring: datasource: url: jdbc:mysql://127.0.0.1:3306/test?useSSL=false username: root password: root driver-class-name: com.mysql.jdbc.Driver type: com.zaxxer.hikari.HikariDataSource hikari: minimum-idle: 3 auto-commit: true idle-timeout: 10000 pool-name: DatebookHikariCP max-lifetime: 1800000 connection-timeout: 30000 jpa: show-sql: true hibernate: ddl-auto: validate