在Wildfly中使用HttpComponents 4.3.6运行应用程序时出现以下错误。我该如何解决这个问题?
Caused by: java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52) [httpcore-4.3.3.jar:4.3.3]
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56) [httpcore-4.3.3.jar:4.3.3]
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46) [httpcore-4.3.3.jar:4.3.3]
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72) [httpclient-4.3.6.jar:4.3.6]
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84) [httpclient-4.3.6.jar:4.3.6]
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59) [httpclient-4.3.6.jar:4.3.6]
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:494) [httpclient-4.3.6.jar:4.3.6]
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149) [httpclient-4.3.6.jar:4.3.6]
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138) [httpclient-4.3.6.jar:4.3.6]
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114) [httpclient-4.3.6.jar:4.3.6]
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726) [httpclient-4.3.6.jar:4.3.6]
at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:58) [httpclient-4.3.6.jar:4.3.6]
答案 0 :(得分:1)
关于该主题的每篇文章都说这是因为不同版本的HttpComponents之间存在冲突。在我的情况下,我导入到我的应用程序的版本与Wildfly提供的版本之间存在冲突。
要解决此问题,您需要一个名为WEB-INF / jboss-deployment-structure.xml的文件,其中包含以下内容:
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.httpcomponents" />
</exclusions>
</deployment>
这将阻止wildfly加载旧版本并干扰您的新版本。
有关详细信息,请参阅https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly。