Home > Java > javaTutorial > Detailed explanation of the problem of disconnection and reconnection of Spring boot database connection in java

Detailed explanation of the problem of disconnection and reconnection of Spring boot database connection in java

怪我咯
Release: 2017-06-30 10:54:51
Original
5622 people have browsed it

This article mainly introduces the problem of Spring boot database connection disconnection and reconnection. Friends in need can refer to the following

Problem description

In this project I am working on, the database is across regions and is not managed by myself. The firewall will automatically disconnect the database every once in a while.

So you need to configure the datasource of application.properties. Ps: I use mybatis to connect to the database.

Configuration and specific meaning

#初始化连接
spring.datasource.initial-size=10
#最大空闲连接
spring.datasource.max-idle=20
#最小空闲连接
spring.datasource.min-idle=5
#最大连接数量
spring.datasource.max-active=50
#是否在自动回收超时连接的时候打印连接的超时错误
spring.datasource.log-abandoned=true
#是否自动回收超时连接
spring.datasource.remove-abandoned=true
#超时时间(以秒数为单位)
spring.datasource.remove-abandoned-timeout=180
##<!-- 超时等待时间以毫秒为单位 6000毫秒/1000等于60秒 -->
spring.datasource.max-wait=1000
spring.datasource.test-while-idle=true
#检测数据库的查询语句
spring.datasource.validation-query=select 1 from dual
spring.datasource.test-on-borrow=true
#每隔五分钟检测空闲超过10分钟的连接
spring.datasource.min-evictable-idle-time-millis=600000
spring.datasource.time-between-eviction-runs-millis=300000
Copy after login

The above is the detailed content of Detailed explanation of the problem of disconnection and reconnection of Spring boot database connection in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template