使用springboot +jdbcTemplate 时运行一段时间后会报错!
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 79,870,633 milliseconds ago.
配置一般的链接pool是无效的,使用官网文档中的jdbc-tomcat 连接pool配置
file table (DataSourceAutoConfiguration & DataSourceProperties) 数据源1
spring.datasource.primary.url=jdbc:mysql://192.168.0.26:3306/yliyun?autoReconnect=true spring.datasource.primary.username=root spring.datasource.primary.password=yliyun123@ spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driver spring.datasource.primary.continue-on-error=false
log table (for log to index); 数据源2
spring.datasource.secondary.url=jdbc:mysql://192.168.0.26:3306/log?autoReconnect=true spring.datasource.secondary.username=root spring.datasource.secondary.password=yliyun123@ spring.datasource.secondary.driver-class-name=com.mysql.jdbc.Driver spring.datasource.secondary.continue-on-error=false
connect pool;
Number of ms to wait before throwing an exception if no connection is available.
spring.datasource.tomcat.max-wait=10000
Maximum number of active connections that can be allocated from this pool at the same time.
spring.datasource.tomcat.max-active=50
Validate the connection before borrowing it from the pool.
spring.datasource.tomcat.test-on-borrow=true
运行后即可