HikariCP

  1. spring:
  2. datasource:
  3. driver-class-name: com.mysql.cj.jdbc.Driver
  4. url: jdbc:mysql://mysql.server.com:3306/paycenter?${mysql-url-params}
  5. type: com.zaxxer.hikari.HikariDataSource
  6. hikari:
  7. minimum-idle: 5
  8. maximum-pool-size: 15
  9. auto-commit: true
  10. pool-name: DatebookHikariCP
  11. connection-timeout: 60000 #30s
  12. validation-timeout: 10000 #5s
  13. idle-timeout: 30000 #10min
  14. max-lifetime: 600000 #30min
  15. connection-test-query: SELECT 1

Druid

  1. <dependency>
  2. <groupId>com.alibaba</groupId>
  3. <artifactId>druid</artifactId>
  4. <version>1.1.12</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.alibaba</groupId>
  8. <artifactId>druid-spring-boot-starter</artifactId>
  9. <version>1.1.17</version>
  10. </dependency>
  11. spring.datasource.druid.url= # 或spring.datasource.url=
  12. spring.datasource.druid.username= # 或spring.datasource.username=
  13. spring.datasource.druid.password= # 或spring.datasource.password=
  14. spring.datasource.druid.driver-class-name= #或 spring.datasource.driver-class-name=
  15. #
  16. spring.datasource.druid.name=DruidPool
  17. spring.datasource.druid.initial-size=1 #0
  18. spring.datasource.druid.min-idle=1
  19. spring.datasource.druid.max-active=8 #8
  20. spring.datasource.druid.max-wait=5000
  21. spring.datasource.druid.validation-query=select 'x'
  22. spring.datasource.druid.validation-query-timeout=3 #秒底层调用jdbc Statement对象的void setQueryTimeout(int seconds)方法
  23. spring.datasource.druid.test-while-idle=true #false 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
  24. # 以下在Oracle下使用
  25. #spring.datasource.druid.pool-prepared-statements=false #false 在mysql下建议关闭
  26. #spring.datasource.druid.max-pool-prepared-statement-per-connection-size=-1
  27. spring.datasource.druid.test-on-borrow=true
  28. spring.datasource.druid.test-on-return=false
  29. spring.datasource.druid.time-between-eviction-runs-millis=1m #1分钟
  30. spring.datasource.druid.min-evictable-idle-time-millis=
  31. spring.datasource.druid.max-evictable-idle-time-millis=
  32. spring.datasource.druid.filters=log4j #配置多个英文逗号分隔

Mybatis

通过@MapperScan(“com.yuque.modules.demo.mapper”),XxxMapper则不需要再增加@Mapper注解