我使用spark-submit将我的jar依赖项提交给spark。在我的jar的main方法中,我想创建HttpAsyncCliens
实例并执行一些请求(apache http async client library):
val httpClient = HttpAsyncClients.custom.setMaxConnTotal(10).setMaxConnPerRoute(10).build
httpClient.start()
httpClient.execute(new HttpGet("https://google.com"), new FutureCallback[HttpResponse] {
/* callbacks */
})
抛出异常:
线程中的异常" pool-1-thread-1" java.lang.NoSuchMethodError: org.apache.http.util.Asserts.check(ZLjava /郎/字符串; Ljava /郎/对象;)V at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:315) at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:191) 在org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase $ 1.run(CloseableHttpAsyncClientBase.java:64) at java.lang.Thread.run(Thread.java:745)thread" main"中的异常java.lang.NoSuchMethodError: org.apache.http.util.Asserts.check(ZLjava /郎/字符串; Ljava /郎/对象;)V at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase.ensureRunning(CloseableHttpAsyncClientBase.java:90) 在org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:123) at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:74) 在org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:107) at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:91) 在spark.Application $ .main(Application.scala:37) 在spark.Application.main(Application.scala) 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:498) 在org.apache.spark.deploy.SparkSubmit $ .org $ apache $ spark $ deploy $ SparkSubmit $$ runMain(SparkSubmit.scala:731) 在org.apache.spark.deploy.SparkSubmit $ .doRunMain $ 1(SparkSubmit.scala:181) 在org.apache.spark.deploy.SparkSubmit $ .submit(SparkSubmit.scala:206) 在org.apache.spark.deploy.SparkSubmit $ .main(SparkSubmit.scala:121) 在org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
似乎我的jar中没有http-core依赖,但我可以在http客户端创建和请求之前或之后在代码中调用此方法(org.apache.http.util.Asserts.check(ZLjava/lang/String;Ljava/lang/Object;)V
):
org.apache.http.util.Asserts.check(true, "test", "test2") // it produces no exception
val httpClient = HttpAsyncClients.custom.setMaxConnTotal(10).setMaxConnPerRoute(10).build
httpClient.start()
httpClient.execute(new HttpGet("https://google.com"), new FutureCallback[HttpResponse] {
/* callbacks */
}) // it produces exception
如果我可以在代码中从同一个类路径调用此方法,为什么会出现NoSuchMethodError?
Apache httpasyncclient v4.1
答案 0 :(得分:1)
这里的解决方案是与spark的直接类路径中的httpcomponents.httpcore版本同步。对于1.6版,版本为4.0.1。
你必须解开火花罐来查看META-INF等等。经过一些侦探工作后,事情会好起来的!