当前问题
跟着老师敲代码添加完配置文件,启动项目进行测试的时候出现报错:
A ResourcePool could not acquire a resource from its primary factory or source.
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
按照网上的办法试了试 1 检查配置文件没有发现问题,跟老师的一摸一样 [main] dataSou=com.mchange.v2.c3p0.ComboPooledDataSource dataSou.driverClass=com.mysql.cj.jdbc.Driver dataSou.jdbcUrl=jdbc:mysql://localhost:3306/shiro?useSSL=false dataSou.user=root dataSou.password=123456 jdbcRealm=org.apache.shiro.realm.jdbc.JdbcRealm jdbcRealm.dataSource=$dataSou securityManager.realm=$jdbcRealm
2 将mysql驱动文件换成mysql-connector-java-8.0.11对应当前mysql版本也不行
3 修改mysql远程访问权限也不行
use mysql;
select host,user from user;
update user set host='%' where user='root';
GRANT ALL ON *.* TO 'root'@'%';
flush privileges;
问题解决
最后我想看是哪段代码会提示A ResourcePool could not acquire a resource from its primary factory or source.
查看源码发现当forceKillAcquires这个值为ture的时候就会出现这个报错,然后百度forceKillAcquires什么情况下会为true的,有篇文章说需要在配置文件中的connecturl添加&serverTimezone=UTC,试了下居然成功解决问题~