HttpClientBuilder - java.lang.NoSuchFieldError:INSTANCE [英] HttpClientBuilder - java.lang.NoSuchFieldError: INSTANCE

查看:812
本文介绍了HttpClientBuilder - java.lang.NoSuchFieldError:INSTANCE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用HttpClient执行HTTP请求的Maven Java项目。在我的本地Java Web Server上,一切正常。但在我将其部署到SAP Hana Cloud Platform后,我收到以下错误:

I have a Maven Java project that uses an HttpClient to execute HTTP requests. On my local Java Web Server everything works fine. But after I deploy it to the SAP Hana Cloud Platform I get the following error:

java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:493)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)
at com.sap.hana.cloud.odata.service.OlingoSampleApp.getHttpclient(OlingoSampleApp.java:382)
at com.sap.hana.cloud.odata.service.OlingoSampleApp.getCsrfToken(OlingoSampleApp.java:374)
at com.sap.hana.cloud.odata.service.ODataCalls.doGet(ODataCalls.java:163)
...

我的依赖关系如下:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.3.5</version>
    <scope>compile</scope>
</dependency>

根据这个问题 Java应用程序中的Mashape Unirest的java.lang.NoSuchFieldError:org.apache.http.message.BasicLineFormatter.INSTANCE 我试过用以下代码获取ClassLoader Ressource。

According to this question java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE from Mashape Unirest in Java application I tried to use the following code to get the ClassLoader Ressource.

ClassLoader classLoader = this.getClass().getClassLoader();
URL resource = classLoader.getResource("org/apache/http/impl/client/HttpClientBuilder.class");
return resource;

并返回以下内容

"jar:file:/some/path/WEB-INF/lib/httpclient-4.3.5.jar!/org/apache/http/impl/client/HttpClientBuilder.class"

您可以看到jar版本是相同的。我看到的每个类似的问题都有不连贯的jar版本作为失败的根源。这个错误还有其他原因吗?

You can see that the jar-versions are the same. Every similar question I looked at had incoherent jar-versions as the source of failure. Could there be another reason for this error?

更新

讨论后在评论中我将更新我的问题:

After the discussion in the comments I'll update my question:

依赖树:

所以现在我看到版本冲突了,我删除了新Java的Web-API 。 classLoader现在再次返回版本4.3.2。但我仍然从一开始就得到错误。

So now I could see the version conflict and I removed the neo-java-web-api. The classLoader now returns version 4.3.2 again. But I still get the error from the beginning.

现在,没有 neo-java-web-api 的新的完整依赖关系树如下所示:

The new, complete dependency tree without the neo-java-web-api now looks like the following:

推荐答案

我仍然无法找到实际问题的解决方案。但至少我可以找到一个解决方法。我将范围更改为< scope>提供< / scope> 并仅使用版本4.1.4中提供的函数。例如 new DefaultHttpClient(cm); 而不是 HttpClientBuilder.create()。build();

I still couldn't find a solution for the actual problem. But at least I could find a workaround. I changed the scope to <scope>provided</scope> and only use functions, which are also available in version 4.1.4. For example new DefaultHttpClient(cm); instead of HttpClientBuilder.create().build();

这篇关于HttpClientBuilder - java.lang.NoSuchFieldError:INSTANCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆