gpt4 book ai didi

spring-boot - 如何在 Spring Boot 应用程序中使用 hikari 配置自动重新连接?

转载 作者:行者123 更新时间:2023-12-04 15:42:53 28 4
gpt4 key购买 nike

我们使用的是 SpringBoot 2.1.x 版本,所以 Hikari 是默认的 DataSource 实现。但是,我不确定如何配置 Hikari 设置以在数据库维护/重启或网络连接问题后自动重新连接到我们的 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。如果不是 - 设置上述属性。

关于spring-boot - 如何在 Spring Boot 应用程序中使用 hikari 配置自动重新连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57105934/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com