String Boot整合hikari连接池

为什么要使用 hikari ? 参考:Springboot 2.0选择HikariCP作为默认数据库连接池的五大理由

1.application.properties方式

spring.datasource.url=${jdbc.url}
spring.datasource.username=${jdbc.username}
spring.datasource.password=${jdbc.password}
# Hikari will use the above plus the following to setup connection pooling
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=15
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1

2.application.yml方式

 

#默认使用配置
spring:
  profiles:
    active: dev
  datasource:
#    The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
#    driver-class-name: com.mysql.jdbc.Driver
    hikari:
      maxLifetime: 1765000 #一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒以上
      maximumPoolSize: 15 #连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
      auto-commit: true
      minimum-idle: 5
      idle-timeout: 30000
      pool-name: hikariDataSource
      connection-timeout: 30000
      connection-test-query: SELECT 1
    type: com.zaxxer.hikari.HikariDataSource
mybatis:
  typeAliasesPackage: com.zhh.model
  mapperLocations: classpath*:mappers/*.xml
#  mapperLocations: classpath*:com/zhh/dao/mapper/*.xml

---
# 开发环境配置
spring:
  profiles: dev
  datasource:
      url: ${jdbc.url}
      username: ${jdbc.username}
      password: ${jdbc.password}

---
# 测试环境配置
spring:
  profiles: test
  datasource:
    url: jdbc:mysql://192.168.0.13:3306/

---
# 生产环境配置
spring:
  profiles: prod
  datasource:
    url: jdbc:mysql://192.168.0.13:3306/
#公共配置与profiles选择无关

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值