SpringBoot多数据源连接池超时配置(MySQL+SQLServer)

单数据源超时配置

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/dcmserver?characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=******
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.max_fetch_depth=1
spring.jpa.hibernate.ddl-auto=none

#MYSQL 8小时连接超时配置
#验证连接的有效性
spring.datasource.test-while-idle=true
#获取连接时候验证,会影响性能
spring.datasource.test-on-borrow=true
spring.datasource.validation-query=SELECT 1 
#空闲连接回收的时间间隔,与test-while-idle一起使用,设置5分钟
spring.datasource.time-between-eviction-runs-millis=300000
#连接池空闲连接的有效时间 ,设置30分钟
spring.datasource.min-evictable-idle-time-millis=1800000

多数据源超时配置

#主数据库
spring.datasource.primary.url=jdbc:mysql://127.0.0.1:3306/dcmserver?characterEncoding=utf-8
spring.datasource.primary.username=root
spring.datasource.primary.password=*****
spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driver
#从数据库
spring.datasource.secondary.url=jdbc:sqlserver://127.0.0.1:1433;database=QZY_PACS
spring.datasource.secondary.username=sa
spring.datasource.secondary.password=******
spring.datasource.secondary.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver


spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.max_fetch_depth=1
spring.jpa.hibernate.ddl-auto=none


#MYSQL 8小时连接超时配置
#验证连接的有效性
spring.datasource.primary.test-while-idle=true
#获取连接时候验证,会影响性能
spring.datasource.primary.test-on-borrow=true
spring.datasource.primary.validation-query=SELECT 1 
#空闲连接回收的时间间隔,与test-while-idle一起使用,设置5分钟
spring.datasource.primary.time-between-eviction-runs-millis=300000
#连接池空闲连接的有效时间 ,设置30分钟
spring.datasource.primary.min-evictable-idle-time-millis=1800000

#SQLServer 连接超时配置
#验证连接的有效性
spring.datasource.secondary.test-while-idle=true
#获取连接时候验证,会影响性能
spring.datasource.secondary.test-on-borrow=true
spring.datasource.secondary.validation-query=SELECT 1 
#空闲连接回收的时间间隔,与test-while-idle一起使用,设置5分钟
spring.datasource.secondary.time-between-eviction-runs-millis=300000
#连接池空闲连接的有效时间 ,设置30分钟
spring.datasource.secondary.min-evictable-idle-time-millis=1800000

猜你喜欢

转载自blog.csdn.net/yan50050/article/details/82630408