当我使用Japser报告生成报告时,我的Spring Boot可以正常工作。
我面临的问题是应用程序引发了休眠异常:
无法获取JDBC连接
多次生成报告后出现此错误。
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
答案 0 :(得分:3)
您的连接用完了。
尝试将Hikari连接池设置为更大的数字:
spring.datasource.hikari.maximum-pool-size=10
答案 1 :(得分:1)
当我使用 jasper 报告时,我确实每 2 天都会遇到同样的问题,并最终通过正确理解来解决它,因为当我们使用基于查询的报告时,我们有责任关闭我们自己的数据源的连接,以便它返回到游泳池并可供下次使用。 你必须照顾多件事 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.maximumPoolSize=30