Java教程

【Spring-BUG记录】数据库连接

本文主要是介绍【Spring-BUG记录】数据库连接,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

项目场景:

创建spring项目在使用maven调用数据库连接依赖时报错


问题描述:

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Caused by: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

十二月 25, 2021 11:25:10 上午 com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl error
严重: create connection error
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

这里是maven配置的依赖有问题,使用的mysql-connector-java依赖版本应该和数据库版本一致

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.11</version>
        </dependency>

然后又报错了,不够这个是另一个错误

Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors


jdbc.url=jdbc:mysql://localhost:3306/goods?serverTimezone=Asia/Shanghai&useSSL=true
这里需要把ssl设置为false

原因分析:


解决方案:

  • 数据库版本要和maven配置mysql-connector-java一致
  • 这里需要把ssl设置为false
这篇关于【Spring-BUG记录】数据库连接的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!