如何在 Spring Boot 应用程序中配置与 hikari 的自动重新连接?

How to configure auto reconnection with hikari in SpringBoot application?

我们使用的是 SpringBoot 2.1.x 版本,因此 Hikari 是默认的 DataSource 实现。但是,我不确定如何配置 Hikari 设置以在数据库 maintenance/restart 或网络连接出现问题后自动重新连接到我们的 Oracle 数据库。

我们有以下 hikari 设置,但它似乎没有帮助。

account.datasource.url: jdbc:oracle:thin:@myserver:1521:DEV
account.datasource.username: user
account.datasource.password: xxxx
account.datasource.driverClassName: oracle.jdbc.driver.OracleDriver

account.datasource.hikari.connection-timeout: 30000
account.datasource.hikari.maximum-pool-size: 3
account.datasource.hikari.idle-timeout: 60000
account.datasource.hikari.max-lifetime: 1800000
account.datasource.hikari.minimum-idle: 2

与数据库的网络连接恢复后重新连接失败。

获取JDBC连接失败;嵌套异常是 java.sql.SQLTransientConnectionException:HikariPool-1 - 连接不可用,请求在 30033 毫秒后超时。

任何其他 account.datasource.hikari.xxxxx 将有助于自动重新连接到数据库?

来自 HikariCP docs:

connectionTestQuery

If your driver supports JDBC4 we strongly recommend not setting this property. This is for "legacy" drivers that do not support the JDBC4 Connection.isValid() API. This is the query that will be executed just before a connection is given to you from the pool to validate that the connection to the database is still alive. Again, try running the pool without this property, HikariCP will log an error if your driver is not JDBC4 compliant to let you know. Default: none

所以我建议验证您的 JDBC 驱动程序实际上是否符合 JDBC4。如果不是 - 设置上面的 属性.