HiKari是目前速度最快的数据库连接池,号称性能最好。
- Spring boot 1.5.7版本使用Hikari数据库连接池。
第一步:引入jar.
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<exclusions>
<exclusion>
<artifactId>tools</artifactId>
<groupId>com.sun</groupId>
</exclusion>
</exclusions>
</dependency>
第二步: 在application.yml文件里做一下配置。
datasource:
url: jdbc:mysql://localhost:3306/tourist?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
name:
username: root
password:
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.zaxxer.hikari.HikariDataSource
hikari:
data-source-properties:
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
配置成功后,启动项目后,会在控制台打印出相关信息。
-
Spring Boot 2.0已经把Hikari作为默认的数据库连接池,所以引用parents后不用专门加依赖。直接做下配置也就可以了。