|
@@ -47,7 +47,14 @@ public class DataSourceConfig {
|
|
|
dataSource.setJdbcUrl(url);
|
|
dataSource.setJdbcUrl(url);
|
|
|
dataSource.setUser(user);
|
|
dataSource.setUser(user);
|
|
|
dataSource.setPassword(password);
|
|
dataSource.setPassword(password);
|
|
|
|
|
+ // 当连接关闭时,不自动提交事务
|
|
|
dataSource.setAutoCommitOnClose(false);
|
|
dataSource.setAutoCommitOnClose(false);
|
|
|
|
|
+ // 设置连接的最大闲置时间 - 5小时(需要小于 mysql 默认的 wait_timeout) 超时则将其回收
|
|
|
|
|
+ dataSource.setMaxIdleTime(18000);
|
|
|
|
|
+ // 设置用于检测数据库连接是否仍有效的SQL
|
|
|
|
|
+ dataSource.setPreferredTestQuery("select 1");
|
|
|
|
|
+ // 设置闲置连接测试周期,保证连接池里的连接都是有效的 - 1 小时(需要小于 mysql 默认的 wait_timeout)
|
|
|
|
|
+ dataSource.setIdleConnectionTestPeriod(3600);
|
|
|
return dataSource;
|
|
return dataSource;
|
|
|
}
|
|
}
|
|
|
|
|
|