Spring Boot默认情况下使用HikariPool的错误问题
来源:爱站网时间:2022-03-30编辑:网友分享
今天带大家来看一看Spring Boot默认情况下使用HikariPool的错误问题内容,希望这篇文章能帮助到朋友们解决问题,接下来就随爱站技术频道小编一探究竟吧!
问题描述
启动SpringBoot应用程序后,在服务器启动的几分钟后出现异常。外部未使用任何HikariPool配置,Spring Boot默认情况下使用HikariPool这是我在控制台中遇到的错误:
2020-02-20 03:16:23 - HikariPool-4 - Failed to validate connection
com.mysql.cj.jdbc.ConnectionImpl@4c4180c8 (No operations allowed after connection closed.).
Possibly consider using a shorter maxLifetime value.
2020-02-20 03:16:28 - HikariPool-4 - Failed to validate connection
com.mysql.cj.jdbc.ConnectionImpl@679c2f50 (No operations allowed after connection closed.).
Possibly consider using a shorter maxLifetime value.
2020-02-20 03:16:33 - HikariPool-4 - Failed to validate connection
com.mysql.cj.jdbc.ConnectionImpl@16083061 (No operations allowed after connection closed.).
Possibly consider using a shorter maxLifetime value.
2020-02-20 03:16:38 - HikariPool-4 - Failed to validate connection
com.mysql.cj.jdbc.ConnectionImpl@4fcaf421 (No operations allowed after connection closed.).
Possibly consider using a shorter maxLifetime value.
2020-02-20 03:16:43 - HikariPool-4 - Failed to validate connection
com.mysql.cj.jdbc.ConnectionImpl@33df5d54 (No operations allowed after connection closed.).
Possibly consider using a shorter maxLifetime value.
2020-02-20 03:16:48 - HikariPool-4 - Failed to validate connection
com.mysql.cj.jdbc.ConnectionImpl@373d288c (No operations allowed after connection closed.).
Possibly consider using a shorter maxLifetime value.
2020-02-20 03:16:48 - SQL Error: 0, SQLState: 08003
2020-02-20 03:16:48 - HikariPool-4 - Connection is not available, request timed out after
30156ms.
2020-02-20 03:16:48 - No operations allowed after connection closed.
2020-02-20 03:16:48 - Servlet.service() for servlet [dispatcherServlet] in context with path
[] threw exception [Request processing failed; nested exception is
org.springframework.dao.DataAccessResourceFailureException: Unable to acquire JDBC
Connection; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to
acquire JDBC Connection] with root cause
思路:
问题是spring.datasource.hikari.maxLifetime的默认值(30分钟-https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby)高于数据库的“ wait_timeout”(在我的情况下为10分钟)。因此,您有两个选择,要么将hikari.maxLifetime降低到10分钟以下,要么增加数据库的“ wait_timeout”属性。
看完这篇Spring Boot默认情况下使用HikariPool的错误问题文章后,对此是否有了不一样的看法。关注爱站技术频道网站,有不懂的可以自行前来查阅。
您可能感兴趣的文章
- 使用外部身份验证源时如何在Spring Boot中模拟身份验证
- 使用PropertySource的每个环境的Spring boot负载配置
- 我可以在Spring Boot中模拟Optional <>的bean吗?
- Spring boot application main方法执行两次->端口已在使用中
- 如何在Spring Boot 2.2.4中与@ConfigurationProperties一起使用@ConstructorBinding和@PropertySource?
- Spring Boot和Azure:在自动配置之前初始化bean
- 无法将spring boot应用程序部署到heroku
- Spring Boot中存储库的默认“ findById”函数的运行时是什么?
- 用于创建Web服务配置的Spring Boot CRUD操作是什么?
- Spring Boot项目中读取yaml配置文件的解决方法