• 解决: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 <clinit>
    信息: 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文件 记得用&amp;来转义&
    /// xml 文件
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test?useSSL=false&amp;characterEncoding=utf8&amp;serverTimezone=UTC"/>
    
    /// properties 文件
    jdbc.url=jdbc:mysql://localhost:3306/test?useSSL=false&characterEncoding=utf8&serverTimezone=UTC
    
  • 相关阅读:
    centos6升级内核
    centos7启动盘制作
    sed匹配字符串并将匹配行的后几行注释
    cmd下调用xshell登录linux服务器
    centos清除历史命令
    yum错误Cannot retrieve metalink for repository: epel/x86_6
    ansible-playbook
    jdk升级到1.8
    shell瞎记录
    shell 循环
  • 原文地址:https://www.cnblogs.com/caophoenix/p/12701849.html
Copyright © 2020-2023  润新知