gpt4 book ai didi

java - HttpClientBuilder 问题 : Could not initialize class sun. security.ssl.SSLContextImpl$CustomizedTLSContext

转载 作者:行者123 更新时间:2023-12-03 22:30:34 26 4
gpt4 key购买 nike

在下面的 java 代码中,我随机收到以下错误。

 final HttpClient client = HttpClientBuilder.create().build();
final HttpGet request = new HttpGet(requestParameters);
final HttpResponse response = client.execute(request);

错误:
java.lang.NoClassDefFoundError: Could not initialize class sun.security.ssl.SSLContextImpl$CustomizedTLSContext
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:291)
at java.base/java.security.Provider$Service.getImplClass(Provider.java:1848)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1824)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:168)
at org.apache.http.ssl.SSLContexts.createDefault(SSLContexts.java:51)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:977)

我无法重现该问题,因为它是随机的。这是否意味着 ssl/tls 握手失败?

实现重试策略是否有助于解决此问题?
  public DefaultHttpRequestRetryHandler() {
this(3, false);
}

https://jar-download.com/artifacts/org.apache.httpcomponents/httpclient/4.5.2/source-code/org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java

以下是我正在使用的 java 库:
enter image description here

更新 : 虽然我认为我可以通过从 HttpClientBuilder 移出来解决这个问题到 java.net.HttpUrlConnection ,不幸的是,我遇到了同样的错误:
java.lang.NoClassDefFoundError: Could not initialize class sun.security.ssl.SSLContextImpl$DefaultSSLContext
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:291)
at java.base/java.security.Provider$Service.getImplClass(Provider.java:1848)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1824)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:168)
at java.base/javax.net.ssl.SSLContext.getDefault(SSLContext.java:99)
at java.base/javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:123)
at java.base/javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(HttpsURLConnection.java:335)
at java.base/javax.net.ssl.HttpsURLConnection.<init>(HttpsURLConnection.java:292)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.<init>(HttpsURLConnectionImpl.java:95)
at java.base/sun.net.www.protocol.https.Handler.openConnection(Handler.java:62)
at java.base/sun.net.www.protocol.https.Handler.openConnection(Handler.java:57)
at java.base/java.net.URL.openConnection(URL.java:1051)

最佳答案

我的 Java 版本是 1.8.0_171。通过升级到 1.8.0_261,同样的问题得到了解决。

关于java - HttpClientBuilder 问题 : Could not initialize class sun. security.ssl.SSLContextImpl$CustomizedTLSContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56531174/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com