gpt4 book ai didi

java - 连接池错误(Spring, hibernate )。如何解决这个问题?

转载 作者:行者123 更新时间:2023-12-01 17:20:05 25 4
gpt4 key购买 nike

WARNING: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@3531a5ff -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 


java.sql.SQLException:无法加载身份验证插件“ caching_sha2_password”。
在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:869)
在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:865)
在com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1746)
在com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
在com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188)
在com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2219)
在com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2014)
在com.mysql.jdbc.ConnectionImpl。(ConnectionImpl.java:776)
在com.mysql.jdbc.JDBC4Connection。(JDBC4Connection.java:47)
在sun.reflect.GeneratedConstructorAccessor36.newInstance(未知来源)
在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
在java.lang.reflect.Constructor.newInstance(Constructor.java:423)
在com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
在com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
在com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
在com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
在com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool $ 1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
在com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
在com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)中
在com.mchange.v2.resourcepool.BasicResourcePool.access $ 700(BasicResourcePool.java:44)
在com.mchange.v2.resourcepool.BasicResourcePool $ ScatteredAcquireTask.run(BasicResourcePool.java:1870)
在com.mchange.v2.async.ThreadPoolAsynchronousRunner $ PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

2020年4月19日,下午11:14:30 com.mchange.v2.resourcepool.BasicResourcePool
警告:com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@456d6127-尝试获取失败!!!清算未完成的收购。在尝试获取所需的新资源时,我们未能成功超过允许的最大尝试获取次数(30)。上次获取尝试异常:
java.sql.SQLException:无法加载身份验证插件“ caching_sha2_password”。
在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:869)
在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:865)
在com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1746)
在com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
在com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188)
在com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2219)
在com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2014)
在com.mysql.jdbc.ConnectionImpl。(ConnectionImpl.java:776)
在com.mysql.jdbc.JDBC4Connection。(JDBC4Connection.java:47)
在sun.reflect.GeneratedConstructorAccessor36.newInstance(未知来源)
在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
在java.lang.reflect.Constructor.newInstance(Constructor.java:423)
在com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
在com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
在com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
在com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
在com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool $ 1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
在com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
在com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)中
在com.mchange.v2.resourcepool.BasicResourcePool.access $ 700(BasicResourcePool.java:44)
在com.mchange.v2.resourcepool.BasicResourcePool $ ScatteredAcquireTask.run(BasicResourcePool.java:1870)
在com.mchange.v2.async.ThreadPoolAsynchronousRunner $ PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

2020年4月19日,下午11:14:30 com.mchange.v2.resourcepool.BasicResourcePool
警告:com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@661ca68e-尝试获取失败!!!清算未完成的收购。在尝试获取所需的新资源时,我们未能成功超过允许的最大尝试获取次数(30)。上次获取尝试异常:
java.sql.SQLException:无法加载身份验证插件“ caching_sha2_password”。
在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:869)
在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:865)
在com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1746)
在com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
在com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188)
在com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2219)
在com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2014)
在com.mysql.jdbc.ConnectionImpl。(ConnectionImpl.java:776)
在com.mysql.jdbc.JDBC4Connection。(JDBC4Connection.java:47)
在sun.reflect.GeneratedConstructorAccessor36.newInstance(未知来源)
在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
在java.lang.reflect.Constructor.newInstance(Constructor.java:423)
在com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
在com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
在com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
在com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
在com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool $ 1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
在com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
在com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)中
在com.mchange.v2.resourcepool.BasicResourcePool.access $ 700(BasicResourcePool.java:44)
在com.mchange.v2.resourcepool.BasicResourcePool $ ScatteredAcquireTask.run(BasicResourcePool.java:1870)
在com.mchange.v2.async.ThreadPoolAsynchronousRunner $ PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

2020年4月19日,下午11:14:30 com.mchange.v2.resourcepool.BasicResourcePool
警告:未能获取资源,com.mchange.v2.resourcepool.BasicResourcePool@7439cf4b正在中断所有等待资源检出的线程。将响应新的客户请求重试。
2020年4月19日,下午11:14:30 com.mchange.v2.resourcepool.BasicResourcePool
警告:未能获取资源,com.mchange.v2.resourcepool.BasicResourcePool@7439cf4b正在中断所有等待资源检出的线程。将响应新的客户请求重试。
2020年4月19日,下午11:14:30 com.mchange.v2.resourcepool.BasicResourcePool
警告:未能获取资源,com.mchange.v2.resourcepool.BasicResourcePool@7439cf4b正在中断所有等待资源检出的线程。将响应新的客户请求重试。
2020年4月19日,下午11:14:30 org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator initializeService
警告:HHH000342:无法获取查询元数据的连接:无法从基础数据库获取连接!
2020年4月19日,下午11:14:30 com.mchange.v2.resourcepool.BasicResourcePool
警告:com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@3aea5402-尝试获取失败!!!清算未完成的收购。在尝试获取所需的新资源时,我们未能成功超过允许的最大尝试获取次数(30)。上次获取尝试异常:
java.sql.SQLException:无法加载身份验证插件“ caching_sha2_password”。
在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:869)
在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:865)
在com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1746)
在com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
在com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188)
在com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2219)
在com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2014)
在com.mysql.jdbc.ConnectionImpl。(ConnectionImpl.java:776)
在com.mysql.jdbc.JDBC4Connection。(JDBC4Connection.java:47)
在sun.reflect.GeneratedConstructorAccessor36.newInstance(未知来源)
在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
在java.lang.reflect.Constructor.newInstance(Constructor.java:423)
在com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
在com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
在com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
在com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
在com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool $ 1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
在com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
在com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)中
在com.mchange.v2.resourcepool.BasicResourcePool.access $ 700(BasicResourcePool.java:44)
在com.mchange.v2.resourcepool.BasicResourcePool $ ScatteredAcquireTask.run(BasicResourcePool.java:1870)
在com.mchange.v2.async.ThreadPoolAsynchronousRunner $ PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

2020年4月19日,下午11:14:30 com.mchange.v2.resourcepool.BasicResourcePool
警告:未能获取资源,com.mchange.v2.resourcepool.BasicResourcePool@7439cf4b正在中断所有等待资源检出的线程。将响应新的客户请求重试。
2020年4月19日,下午11:14:30 com.mchange.v2.resourcepool.BasicResourcePool
警告:com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@4f3eb158-尝试获取失败!!!清算未完成的收购。在尝试获取所需的新资源时,我们未能成功超过允许的最大尝试获取次数(30)。上次获取尝试异常:
java.sql.SQLException:无法加载身份验证插件“ caching_sha2_password”。
在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:869)
在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:865)
在com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1746)
在com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226)
在com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188)
在com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2219)
在com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2014)
在com.mysql.jdbc.ConnectionImpl。(ConnectionImpl.java:776)
在com.mysql.jdbc.JDBC4Connection。(JDBC4Connection.java:47)
在sun.reflect.GeneratedConstructorAccessor36.newInstance(未知来源)
在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
在java.lang.reflect.Constructor.newInstance(Constructor.java:423)
在com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
在com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
在com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
在com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
在com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
在com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool $ 1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
在com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
在com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)中
在com.mchange.v2.resourcepool.BasicResourcePool.access $ 700(BasicResourcePool.java:44)
在com.mchange.v2.resourcepool.BasicResourcePool $ ScatteredAcquireTask.run(BasicResourcePool.java:1870)
在com.mchange.v2.async.ThreadPoolAsynchronousRunner $ PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

2020年4月19日,下午11:14:30 com.mchange.v2.resourcepool.BasicResourcePool
警告:未能获取资源,com.mchange.v2.resourcepool.BasicResourcePool@7439cf4b正在中断所有等待资源检出的线程。将响应新的客户请求重试。
2020年4月19日11:14:30 PM org.hibernate.dialect.Dialect
INFO:HHH000400:使用方言:org.hibernate.dialect.MySQLDialect

这是我的代码

@Autowired
private Environment env;

private Logger logger = Logger.getLogger(getClass().getName());

// define a bean for ViewResolver

@Bean
public DataSource myDataSource() {

// create connection pool
ComboPooledDataSource myDataSource = new ComboPooledDataSource();

// set the jdbc driver
try {
myDataSource.setDriverClass("com.mysql.jdbc.Driver");
}
catch (PropertyVetoException exc) {
throw new RuntimeException(exc);
}

// for sanity's sake, let's log url and user ... just to make sure we are reading the data
logger.info("jdbc.url=" + env.getProperty("jdbc.url"));
logger.info("jdbc.user=" + env.getProperty("jdbc.user"));

// set database connection props
myDataSource.setJdbcUrl(env.getProperty("jdbc.url"));
myDataSource.setUser(env.getProperty("jdbc.user"));
myDataSource.setPassword(env.getProperty("jdbc.password"));

// set connection pool props
myDataSource.setInitialPoolSize(getIntProperty("connection.pool.initialPoolSize"));
myDataSource.setMinPoolSize(getIntProperty("connection.pool.minPoolSize"));
myDataSource.setMaxPoolSize(getIntProperty("connection.pool.maxPoolSize"));
myDataSource.setMaxIdleTime(getIntProperty("connection.pool.maxIdleTime"));

return myDataSource;
}

private Properties getHibernateProperties() {

// set hibernate properties
Properties props = new Properties();

props.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
props.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql"));

return props;
}


// need a helper method
// read environment property and convert to int

private int getIntProperty(String propName) {

String propVal = env.getProperty(propName);

// now convert to int
int intPropVal = Integer.parseInt(propVal);

return intPropVal;
}

@Bean
public LocalSessionFactoryBean sessionFactory(){

// create session factories
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();

// set the properties
sessionFactory.setDataSource(myDataSource());
sessionFactory.setPackagesToScan(env.getProperty("hibernate.packagesToScan"));
sessionFactory.setHibernateProperties(getHibernateProperties());

return sessionFactory;
}

@Bean
@Autowired
public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {

// setup transaction manager based on session factory
HibernateTransactionManager txManager = new HibernateTransactionManager();
txManager.setSessionFactory(sessionFactory);

return txManager;
}


}

我怎样才能解决这个问题 ?

最佳答案

您的问题是您的池中没有免费的数据库连接。我不知道它在休眠状态下如何工作。但是您应该注意数据库访问。使用后应关闭连接。在JDBC中,只需使用“尝试资源”(try() {...})打开它,或使用“ finally”块来关闭连接。

关于java - 连接池错误(Spring, hibernate )。如何解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61311800/

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