JDBCConnectionException "Unable to acquire JDBC Connection" 与 spring 启动
JDBCConnectionException "Unable to acquire JDBC Connection" with spring boot
当我使用 Japser 报告生成报告时,我的 Spring 引导工作正常。
我遇到的问题是应用程序抛出 hibernate 异常 :
Unable to acquire JDBC Connection
我多次生成报告后出现此错误。
1 running delayed actions on {type: MASTER, group: null, band: 0}
2018-09-20 14:27:55.536 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.fill.JRBaseFiller : Fill 1: ended
2018-09-20 14:27:55.536 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.fill.JRFillDataset : Fill 1: closing query executer
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block DEVANAGARI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block BENGALI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block TELUGU
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block TAMIL
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block GUJARATI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block KANNADA
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block MALAYALAM
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block ORIYA
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block GURMUKHI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block SINHALA
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block TIBETAN
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block KHMER
2018-09-20 14:28:25.549 WARN 46148 --- [ XNIO-2 task-27]
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: null
2018-09-20 14:28:25.550 ERROR 46148 --- [ XNIO-2 task-27]
o.h.engine.jdbc.spi.SqlExceptionHelper : HikariPool-1 - Connection is not
available, request timed out after 30000ms.
2018-09-20 14:28:25.556 ERROR 46148 --- [ XNIO-2 task-27]
c.n.xx.aop.logging.LoggingAspect : Exception in
com.xx.xx.web.rest.GrueResource.generateRapportGrue() with cause =
'org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC
Connection' and exception = 'Could not open JPA EntityManager for
transaction; nested exception is
org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC
Connection'
org.springframework.transaction.CannotCreateTransactionException: Could not
open JPA EntityManager for transaction; nested exception is
org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC
Connection
你 运行 没有联系。
尝试将 Hikari 连接池设置为更大的数字:
spring.datasource.hikari.maximum-pool-size=10
当我使用 jasper 报告时,我确实每 2 天都会遇到同样的问题,并最终通过正确的理解解决了它,因为当我们使用基于查询的报告时,我们有责任关闭我们自己的数据源连接,以便它 return 到池中并可供下次使用。
你必须处理好几件事
1- 从数据源获取连接
DataSourceUtils.getConnection(ds);
2-在任何情况下您都必须关闭数据源连接:最好在 finally 块 中关闭它,以便在异常情况下连接不会保持打开状态。
finally{closeConnection(con,dataSource);}
public void closeConnection(Connection con,DataSource ds) {
if (con != null) {
DataSourceUtils.releaseConnection(con, ds);
}
}
3-在 application.properties 文件中进行了更改
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.maxLifetime=1800000
spring.datasource.hikari.maximumPoolSize=30
当我使用 Japser 报告生成报告时,我的 Spring 引导工作正常。
我遇到的问题是应用程序抛出 hibernate 异常 :
Unable to acquire JDBC Connection
我多次生成报告后出现此错误。
1 running delayed actions on {type: MASTER, group: null, band: 0}
2018-09-20 14:27:55.536 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.fill.JRBaseFiller : Fill 1: ended
2018-09-20 14:27:55.536 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.fill.JRFillDataset : Fill 1: closing query executer
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block DEVANAGARI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block BENGALI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block TELUGU
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block TAMIL
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block GUJARATI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block KANNADA
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block MALAYALAM
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block ORIYA
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block GURMUKHI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block SINHALA
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block TIBETAN
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27]
n.s.j.engine.export.JRPdfExporter : glyph renderer block KHMER
2018-09-20 14:28:25.549 WARN 46148 --- [ XNIO-2 task-27]
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: null
2018-09-20 14:28:25.550 ERROR 46148 --- [ XNIO-2 task-27]
o.h.engine.jdbc.spi.SqlExceptionHelper : HikariPool-1 - Connection is not
available, request timed out after 30000ms.
2018-09-20 14:28:25.556 ERROR 46148 --- [ XNIO-2 task-27]
c.n.xx.aop.logging.LoggingAspect : Exception in
com.xx.xx.web.rest.GrueResource.generateRapportGrue() with cause =
'org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC
Connection' and exception = 'Could not open JPA EntityManager for
transaction; nested exception is
org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC
Connection'
org.springframework.transaction.CannotCreateTransactionException: Could not
open JPA EntityManager for transaction; nested exception is
org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC
Connection
你 运行 没有联系。
尝试将 Hikari 连接池设置为更大的数字:
spring.datasource.hikari.maximum-pool-size=10
当我使用 jasper 报告时,我确实每 2 天都会遇到同样的问题,并最终通过正确的理解解决了它,因为当我们使用基于查询的报告时,我们有责任关闭我们自己的数据源连接,以便它 return 到池中并可供下次使用。 你必须处理好几件事 1- 从数据源获取连接
DataSourceUtils.getConnection(ds);
2-在任何情况下您都必须关闭数据源连接:最好在 finally 块 中关闭它,以便在异常情况下连接不会保持打开状态。
finally{closeConnection(con,dataSource);}
public void closeConnection(Connection con,DataSource ds) {
if (con != null) {
DataSourceUtils.releaseConnection(con, ds);
}
}
3-在 application.properties 文件中进行了更改
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.maxLifetime=1800000
spring.datasource.hikari.maximumPoolSize=30