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後不用專門加依賴。直接做下配置也就可以了。