簡體   English   中英

引起:java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLConnectionSocketFactory

[英]caused by: java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLConnectionSocketFactory

我正在使用帶有 HttpClient 的 Spring Boot、Spring MVC 和 Spring Web。 在嘗試在 @Configuration 類中創建HttpClient對象時,我收到以下代碼的異常:

SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
    Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.getSocketFactory())
            .register("https", sslSocketFactory)
            .build();

POM 依賴

<properties>
  <http.client>4.5.2</http.client>
  <http.core>4.4.4</http.core>
</<properties>
 <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>${http.core}</version>
        </dependency>
<dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${http.client}</version>
        </dependency>

例外

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.http.client.HttpClient]: Factory method 'getHttpClient' thr
ew exception; nested exception is java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLConnectionSocketFactory.<init>(Ljavax/net/ssl/SSLContext;Ljavax/net
/ssl/HostnameVerifier;)V                                                                                                                                      
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)                            
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)                          
        ... 155 more                                                                                                                                          
Caused by: java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLConnectionSocketFactory.<init>(Ljavax/net/ssl/SSLContext;Ljavax/net/ssl/HostnameVerifier;)
V                                                                                                                                                             
        at wsclient.RestClientConfig.getHttpClient(RestClientConfig.java:182)                                                         
        at wsclient.RestClientConfig$$EnhancerBySpringCGLIB$$d3a9da1b.CGLIB$getHttpClient$2(<generated>)                              
        at wsclient.RestClientConfig$$EnhancerBySpringCGLIB$$d3a9da1b$$FastClassBySpringCGLIB$$a56984ae.invoke(<generated>)           
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)                                                                      
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)             
        at wsclient.RestClientConfig$$EnhancerBySpringCGLIB$$d3a9da1b.getHttpClient(<generated>)                                      
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                                        
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)                                                                      
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                                              
        at java.lang.reflect.Method.invoke(Method.java:497)                                                                                                   
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)                            
        ... 156 more 

任何幫助或建議表示贊賞

我能夠使用此源找到庫沖突的源:

“這很奇怪,也許它正在從不同的 jar 加載 Apache 類。你能嘗試運行以下命令並粘貼輸出嗎?它可能會給我們一個線索,它試圖從哪里獲取這些類:org.apache.http.conn.ssl .SSLConnectionSocketFactory.class.getProtectionDomain().getCodeSource().getLocation().getPath()"

找到位置后,結果是我的/.m2/repository/文件夾中的另一個 jar 文件,然后我清理了該文件夾,因此現在它指的是/org/apache/httpcomponents/httpclient/4.5.6/httpclient -4.5.6.jar罐子。

原始來源: https : //github.com/aws/aws-sdk-java/issues/938

刪除顯式的httpcore依賴項(它將包含在httpclient )並執行mvn clean install 如果問題仍然存在,請顯示您的完整 POM,因為您可能安裝了與其他內容沖突的httpclient版本。

我遇到過類似的問題。 首先加載了一個舊的 httpClient jar。 更換那個罐子后,它工作正常。

java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLConnectionSocketFactory.(Ljavax/net/ssl/SSLContext;Ljavax/net/ssl/HostnameVerifier;)V

錯誤

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM