解决:CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.

log4j给出的异常信息有下面几句:

Caused by: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
	at ...
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
	at ...
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
	at ...

多半是关于数据库的配置有问题

刚开始网上查了很多资料还是百思不得其解,从 pom 中把log4jslf4j-apislf4j-log4j12等依赖去掉(从log4j切换成了默认日志),才看到下面这个异常信息,这才明白是url里需要加上时区参数。

四月 16, 2020 8:36:09 下午 com.mchange.v2.log.MLog 
信息: MLog clients using java 1.4+ standard logging.
...
java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone.

关于数据库配置的几个建议:

  • mysql-connector-java-8.x.x-bin.jar的驱动com.mysql.cj.jdbc.Driver连接MySQL 8
  • URL 最好带上characterEncodingserverTimezone,还可以指明是否进行SSL连接useSSL=false:(XML文件 记得用&来转义&
/// xml 文件


/// properties 文件
jdbc.url=jdbc:mysql://localhost:3306/test?useSSL=false&characterEncoding=utf8&serverTimezone=UTC

你可能感兴趣的:(解决:CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.)