Spring 4中的HttpClient bean创建错误

时间:2018-02-28 20:46:30

标签: java spring tomcat spring-boot websphere

我正在尝试使用以下代码建立到HTTPs休息服务的SSL连接。下面的代码在我的本地系统中的webServer tomcat中运行良好。 但是当我尝试在运行webphere的开发环境中部署它时,我的战争是为数不多的其他战争之一。我得到了错误。描述如下。错误发生在httpClient bean中。 我的Bean创建代码:

@Configuration
public class SSLRestConfiguration {
    @Bean
    public HttpClient httpClient() {

        String url = "https:://vm-ab12-cd34";
        String trustStorePwd = "changeit";
        String trustStore = "src/resources/cacert/cacerts";  // CACert location relative path

        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(new FileInputStream(new File(trustStore)), trustStorePwd);
        SSLSocketFactory socketFactory = new SSLSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignStrategy())
                                                    .loadKeyMaterial(keyStore,trustStorePwd.toCharArray()).build(), NoopHostnameVerifier.Instance);
        HttpClient httpClient = HttpsClient.custom().setSSLSocketFactory(socketFactory).build();
        return httpClient;      
    }
}

我得到的错误如下:

caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate[org.apache.http.client.HttpClient] factory method 'httpClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/http/util/args
.. at 
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
.. at org.springframework.expression.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)..

有人可以帮助解决为什么它在Application Server上不起作用? 我坚持这个错误,无法前进。

1 个答案:

答案 0 :(得分:0)

我已在我的项目中解决了这个问题。在下面发布答案,以便将来可以帮助某人。

  1. 我们正在使用WASCE。
  2. 当我检查更改其中的类加载器策略时。它在服务器的配置中不可用。
  3. 而是应该在战争的geronimo.xml中覆盖问题出现的包。这与更改类加载器策略完全相同。
  4. 这解决了我面临的问题。
  5. 希望这有帮助。