gpt4 book ai didi

java - 无法创建池的初始连接,无法获取 JDBC 连接错误

转载 作者:太空宇宙 更新时间:2023-11-04 09:09:34 24 4
gpt4 key购买 nike

我有一个 Spring Boot 数据 JPA 应用程序,我正在其中创建两个数据源。当我的应用程序启动时,我收到此错误。

1. org.apache.tomcat.jdbc.pool.ConnectionPool init
SEVERE: Unable to create initial connections of pool.
java.sql.SQLException
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:253)
2. Caused by: java.lang.NullPointerException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:245)
... 88 more

3. Jan 20, 2020 7:39:29 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: null
[http-bio-8080-exec-1] ERROR org.springframework.boot.web.support.ErrorPageFilter - Forwarding to error page from request [/orderForDateTopK/1/2] due to exception [Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection]
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:431)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)

4. Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692)

5. Caused by: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection

最佳答案

您使用 Tomcat JDBC 连接池作为数据源,但在 application.properties 中为 Hikari 数据源配置连接池

由于连接池设置的原因,您的数据源未正确实例化。

您的错误配置:

#HikariCP settings
spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.maximum-pool-size=15
spring.datasource.hikari.minimum-idle=1
<小时/>

您有 2 个解决方案

1- Change your connection pool settings from hikari to tomcat

像这样

spring.datasource.tomcat.initial-size=
spring.datasource.tomcat.max-wait=
spring.datasource.tomcat.max-active=
spring.datasource.tomcat.max-idle=
spring.datasource.tomcat.min-idle=
spring.datasource.tomcat.default-auto-commit=
//..

该领域的一些有用指南:

<强> Configuring a Tomcat Connection Pool

2- Use Hikari Connection Pool instead of tomcat (Change datasource connection pool)

该领域的一些有用指南:

<强> A Simple Guide to Connection Pooling in Java

<强> Introduction to HikariCP

关于java - 无法创建池的初始连接,无法获取 JDBC 连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59825300/

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