我有spring boot 2应用,我正在使用Flyway进行数据库迁移。我在应用程序启动时以编程方式执行了飞行路线迁移。这样做时,我得到: java.lang.Exception:检测到明显的连接泄漏
在行上:
Database database = org.flywaydb.core.internal.database.DatabaseFactory.createDatabase(flyway, false);
这是我的Hikari CP配置:
spring.datasource.max-active=20
spring.datasource.idle-timeout=10000
spring.datasource.initial-size=20
spring.datasource.test-on-return=true
spring.datasource.hikari.leak-detection-threshold=10000
答案 0 :(得分:0)
因此,Flyway显然不会关闭连接。解决方案是手动处理:
try (Database database = DatabaseFactory.createDatabase(flyway, false)) {
database.getMainConnection(); // this is important, otherwise there will be connection leak
doRunMigrations(database);
}