欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java.security.cet.CertPathValidatorException: Path does not chain with any of the trust anchors 解决办法

程序员文章站 2022-04-05 09:53:05
...

问题简介:

项目使用的是 Spring Boot + Mybatis + MySQL 进行开发的,数据库访问使用 Spring Boot Data JPA ,主要用于简化 RDBMS 关系型数据库的访问与CRUD 操作。但是在启动项目时,启动失败,证书路径验证器异常 ,异常信息如下:

Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1937)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
    at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1478)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:212)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:969)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:904)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1050)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1363)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1391)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1375)
    at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:186)
    ... 153 common frames omitted
Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
    at com.mysql.jdbc.ExportControlled$X509TrustManagerWrapper.checkServerTrusted(ExportControlled.java:302)
    at sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(SSLContextImpl.java:922)
    at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1460)
    ... 161 common frames omitted
Caused by: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
    at sun.security.provider.certpath.PKIXCertPathValidator.validate(PKIXCertPathValidator.java:153)
    at sun.security.provider.certpath.PKIXCertPathValidator.engineValidate(PKIXCertPathValidator.java:79)
    at java.security.cert.CertPathValidator.validate(CertPathValidator.java:292)
    at com.mysql.jdbc.ExportControlled$X509TrustManagerWrapper.checkServerTrusted(ExportControlled.java:295)
    ... 163 common frames omitted
14:03:23.865 [restartedMain] ERROR c.a.d.p.DruidDataSource - [init,905] - {dataSource-1} init error
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

部分截图如下:
java.security.cet.CertPathValidatorException: Path does not chain with any of the trust anchors 解决办法

解决办法:

通常,我们连接数据库时,为了数据传输的安全性,都开启了证书的校验,如下图:
java.security.cet.CertPathValidatorException: Path does not chain with any of the trust anchors 解决办法

这儿只需要将证书的校验关闭即可,修改 useSSL=false
关于这个解决办法,只是解决了燃眉之急,让项目跑起来,具体的问题还在深入的探索中,如果那位仁兄有更好的问题探究和深入的解决方案,欢迎留言,在此万分感激!!!


好了,关于 java.security.cet.CertPathValidatorException: Path does not chain with any of the trust anchors 解决办法 就写到这儿了,如果还有什么疑问或遇到什么问题欢迎扫码提问,也可以给我留言哦,我会一一详细的解答的。
歇后语:“ 共同学习,共同进步 ”,也希望大家多多关注CSND的IT社区。