HikariCP
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://mysql.server.com:3306/paycenter?${mysql-url-params}
type: com.zaxxer.hikari.HikariDataSource
hikari:
minimum-idle: 5
maximum-pool-size: 15
auto-commit: true
pool-name: DatebookHikariCP
connection-timeout: 60000 #30s
validation-timeout: 10000 #5s
idle-timeout: 30000 #10min
max-lifetime: 600000 #30min
connection-test-query: SELECT 1
Druid
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.17</version>
</dependency>
spring.datasource.druid.url= # 或spring.datasource.url=
spring.datasource.druid.username= # 或spring.datasource.username=
spring.datasource.druid.password= # 或spring.datasource.password=
spring.datasource.druid.driver-class-name= #或 spring.datasource.driver-class-name=
#
spring.datasource.druid.name=DruidPool
spring.datasource.druid.initial-size=1 #0
spring.datasource.druid.min-idle=1
spring.datasource.druid.max-active=8 #8
spring.datasource.druid.max-wait=5000
spring.datasource.druid.validation-query=select 'x'
spring.datasource.druid.validation-query-timeout=3 #秒底层调用jdbc Statement对象的void setQueryTimeout(int seconds)方法
spring.datasource.druid.test-while-idle=true #false 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
# 以下在Oracle下使用
#spring.datasource.druid.pool-prepared-statements=false #false 在mysql下建议关闭
#spring.datasource.druid.max-pool-prepared-statement-per-connection-size=-1
spring.datasource.druid.test-on-borrow=true
spring.datasource.druid.test-on-return=false
spring.datasource.druid.time-between-eviction-runs-millis=1m #1分钟
spring.datasource.druid.min-evictable-idle-time-millis=
spring.datasource.druid.max-evictable-idle-time-millis=
spring.datasource.druid.filters=log4j #配置多个英文逗号分隔
Mybatis
通过@MapperScan(“com.yuque.modules.demo.mapper”),XxxMapper则不需要再增加@Mapper注解