且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效认证路径

更新时间:2021-12-12 02:52:41

当您的服务器具有自签名证书时出现该问题.要解决此问题,您可以将此证书添加到 JVM 的受信任证书列表中.

The problem appears when your server has self signed certificate. To workaround it you can add this certificate to the list of trusted certificates of your JVM.

在本文中作者介绍了如何从您的浏览器并将其添加到 JVM 的 cacerts 文件中.您可以编辑 JAVA_HOME/jre/lib/security/cacerts 文件或使用 -Djavax.net.ssl.trustStore 参数运行您的应用程序.验证您也在使用哪个 JDK/JRE,因为这通常是混淆的根源.

In this article author describes how to fetch the certificate from your browser and add it to cacerts file of your JVM. You can either edit JAVA_HOME/jre/lib/security/cacerts file or run you application with -Djavax.net.ssl.trustStore parameter. Verify which JDK/JRE you are using too as this is often a source of confusion.

另见:SSL 证书服务器名称如何解析/我可以使用 keytool 添加替代名称吗? 如果您遇到 java.security.cert.CertificateException: No name matching localhost found 异常.

See also: How are SSL certificate server names resolved/Can I add alternative names using keytool? If you run into java.security.cert.CertificateException: No name matching localhost found exception.