SpringBoot数据源HikariCP与MyBatis整合
2019-12-10 本文已影响0人
_灯火阑珊处
SpringBoot2默认数据库连接池为HikariCP
HikariCP GitHub地址
image.pngpom文件:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
配置文件
server:
port: 8888
tomcat:
uri-encoding: UTF-8
max-http-header-size: 80KB
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/testDb?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true
username: root
password: 123456
hikari:
connection-timeout: 30000 # 等待连接池分配连接的最大时长(毫秒)
minimum-idle: 5 # 最小连接数
maximum-pool-size: 20 # 最大连接数
auto-commit: true # 是否自动提交
idle-timeout: 600000 # 连接超时的最大时长(毫秒)
pool-name: DateSourceHikariCP # 连接池名称
max-lifetime: 1800000 # 连接的生命时长(毫秒)
connection-test-query: SELECT 1 # 连接测试sql
mybatis:
type-aliases-package: com.test.pojo
mapper-locations: classpath:mapper/*.xml