SpringBoot数据库连接池常用配置(mysql+sqlServer)
在實(shí)際項(xiàng)目中應(yīng)用的雙數(shù)據(jù)源配置
#mySql
#first datasource
spring.datasource.master.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.master.url=jdbc:mysql://127.0.0.1:3306/mysql_test?characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false
spring.datasource.master.username=root
spring.datasource.master.password=123456
# Hikari will use the above plus the following to setup connection pooling
# 數(shù)據(jù)源類型
spring.datasource.master.type=com.zaxxer.hikari.HikariDataSource
#最小空閑連接,默認(rèn)值10,小于0或大于maximum-pool-size,都會(huì)重置為maximum-pool-size
spring.datasource.master.hikari.minimum-idle=5
#最大連接數(shù),小于等于0會(huì)被重置為默認(rèn)值10;大于零小于1會(huì)被重置為minimum-idle的值
spring.datasource.master.hikari.maximum-pool-size=15
spring.datasource.master.hikari.auto-commit=true
# 只有空閑連接數(shù)大于最大連接數(shù)且空閑時(shí)間超過(guò)該值,才會(huì)被釋放
spring.datasource.master.hikari.idle-timeout=30000
#連接池名稱,默認(rèn)HikariPool-1
spring.datasource.master.hikari.pool-name=DatebookHikariCP
#連接最大存活時(shí)間.不等于0且小于30秒,會(huì)被重置為默認(rèn)值30分鐘.設(shè)置應(yīng)該比mysql設(shè)置的超時(shí)時(shí)間短
spring.datasource.master.hikari.max-lifetime=1800000
#連接超時(shí)時(shí)間:毫秒,小于250毫秒,否則被重置為默認(rèn)值30秒
spring.datasource.master.hikari.connection-timeout=30000
#連接測(cè)試查詢
spring.datasource.master.hikari.connection-test-query=SELECT 1
?
#sqlServer
#secode datasource
spring.datasource.other.url=jdbc:sqlserver://127.0.0.1:1433;DatabaseName=sqlserver_test
spring.datasource.other.username=sa
spring.datasource.other.password=123456
#use druid datasource
spring.datasource.other.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.other.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
#SQLServer 連接超時(shí)配置
#驗(yàn)證連接的有效性
spring.datasource.other.test-while-idle=true
#獲取連接時(shí)候驗(yàn)證,會(huì)影響性能
spring.datasource.other.test-on-borrow=true
spring.datasource.other.validation-query=SELECT 1
#空閑連接回收的時(shí)間間隔,與test-while-idle一起使用,設(shè)置5分鐘
spring.datasource.other.time-between-eviction-runs-millis=300000
#連接池空閑連接的有效時(shí)間 ,設(shè)置30分鐘
spring.datasource.other.min-evictable-idle-time-millis=1800000
#指定啟動(dòng)連接池時(shí),初始建立的連接數(shù)量
spring.datasource.other.initial-size=5
#指定連接池中最大的活躍連接數(shù).
spring.datasource.other.max-active=10
#指定連接池等待連接返回的最大等待時(shí)間,毫秒單位.
spring.datasource.other.max-wait=60000
#指定必須保持連接的最小值
spring.datasource.other.min-idle=3
#指定連接池最大的空閑連接數(shù)量
spring.datasource.other.max-idle=10
總結(jié)
以上是生活随笔為你收集整理的SpringBoot数据库连接池常用配置(mysql+sqlServer)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: this的指向为什么是undefined
- 下一篇: linux cmake编译源码,linu