java - 将 Hibernate Search 与 Spring 应用程序一起使用时连接已关闭
问题描述
由于我在我的应用程序上添加了 Hibernate Search,似乎我在一段时间后失去了与 Hikari 池的连接(似乎超过 8 小时)
我整整一周都在为这个错误苦苦挣扎,但我真的不知道为什么会这样:
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not prepare statement
Caused by: org.hibernate.exception.GenericJDBCException: could not prepare statement
Caused by: java.sql.SQLException: Connection is closed
我试过:设置一些光的属性,如:
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimumIdle=20
spring.datasource.hikari.maximumPoolSize=100
spring.datasource.hikari.idleTimeout=300000
spring.datasource.hikari.poolName=SpringBootJPAHikariCP
spring.datasource.hikari.maxLifetime=200000
spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.registerMbeans=true
将我的 bean 配置为使用如下所示的 testQuery:
public DataSource siteDataSource() {
HikariConfig config = new HikariConfig();
HikariDataSource dataSource;
config.setJdbcUrl(env.getProperty("spring.mysql.datasource.url"));
config.setUsername(env.getProperty("spring.mysql.datasource.username"));
config.setPassword(env.getProperty("spring.mysql.datasource.password"));
config.setDriverClassName(env.getProperty("spring.mysql.datasource.driver-class-name"));
config.setMaximumPoolSize(15);
config.setConnectionTestQuery("SELECT 1");
// performance senstive settings
config.setMinimumIdle(0);
config.setConnectionTimeout(30000);
config.setIdleTimeout(35000);
config.setMaxLifetime(45000);
dataSource = new HikariDataSource(config);
return dataSource;
}
(这个配置的东西也被删除了,错误仍然一样)
并使用:
autoReconnect=true
我也得到了下面的错误,这似乎在当前的实现中消失了(但老实说,我不知道为什么 - 是的,我在这里很迷茫):
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: The last packet successfully received from the server was 50,090,585 milliseconds ago. The last packet sent successfully to the server was 50,090,585 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
我什至不知道如何重现此错误。我必须等待一整天才能为每个新测试再次测试它。
似乎与Tomcat + Hibernate + Hikari有关,但老实说,我没有任何进一步的想法。
你们知道如何解决这个问题,甚至如何在短时间内重现这个错误吗?
谢谢。
解决方案
帮助我们解决相同问题的步骤:
- 升级你的 SpringBoot 版本。
- 升级您的数据库连接器库版本。
- 删除其他数据库连接池库,通常应该使用 SpringBoot 中的默认 Hikari。
推荐阅读
- c - 无法到达c中的第一位字符
- angular - 在具有自定义文本类别的 Angular Kendo 柱形图中为 categoryAxis 添加可平移选项
- r-modis - runGdal 开始日期问题
- vb.net - VB.NET 休息客户端 POST -d 正文
- java - MongoDB为大写键返回空值
- django - 如何在模型中注释来自其他模型的聚合
- php - 根据星期几禁用特定类别中所有产品的购买按钮
- azure - 我必须验证后端服务吗?
- javascript - 压缩字符串不适用于所有字符串
- google-apps-script - 需要在 Google Apps 脚本中获取图表系列