从 Spark Streaming 中使用 HttpSolrServer (httpclient) 时出现异常:java.lang.NoSuchMethodError

Exception when using HttpSolrServer (httpclient) from within Spark Streaming: java.lang.NoSuchMethodError

我正在使用 Spark 1.1.0Solr 4.10.3。在 Spark Streaming 中使用 HttpSolrServer 时出现异常:

java.lang.NoSuchMethodError: org.apache.http.impl.conn.SchemeRegistryFactory.createSystemDefault()Lorg/apache/http/conn/scheme/SchemeRegistry

通常,当我使用我的实用程序 class 时,该实用程序使用 SolrJ 连接到 Solr 服务器并 运行 它本身(运行 在没有 Spark 的情况下独立运行),一切正常。

但是当我在 Spark Streaming 应用程序中调用该实用程序 class 时,我在它尝试与 Solr 服务器建立连接时立即收到上述异常。

我的初步互联网搜索让我相信一些 Spark 或 Hadoop 组件带来了旧版本的 httpclient,所以我试图在我的 pom.xml 中排除它们].

但我仍然遇到同样的异常。

知道为什么吗?我该怎么办?

当我分析我的 pom.xml 依赖项时,我得到:

$ mvn dependency:tree -Ddetail=true | grep http
[INFO] |  |  \- org.eclipse.jetty:jetty-http:jar:8.1.14.v20131031:provided
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.3.1:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.3:compile
[INFO] |  +- org.apache.httpcomponents:httpmime:jar:4.3.1:compile

整个依赖关系树是:

$ mvn dependency:tree -Ddetail=true
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building bigcontent 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ bigcontent ---
[INFO] bigcontent:bigcontent:jar:1.0-SNAPSHOT
[INFO] +- org.apache.spark:spark-streaming_2.10:jar:1.1.1:provided
[INFO] |  +- org.apache.spark:spark-core_2.10:jar:1.1.1:provided
[INFO] |  |  +- org.apache.curator:curator-recipes:jar:2.4.0:provided
[INFO] |  |  |  \- org.apache.curator:curator-framework:jar:2.4.0:provided
[INFO] |  |  |     \- org.apache.curator:curator-client:jar:2.4.0:provided
[INFO] |  |  +- org.eclipse.jetty:jetty-plus:jar:8.1.14.v20131031:provided
[INFO] |  |  |  +- org.eclipse.jetty.orbit:javax.transaction:jar:1.1.1.v201105210645:provided
[INFO] |  |  |  +- org.eclipse.jetty:jetty-webapp:jar:8.1.14.v20131031:provided
[INFO] |  |  |  |  +- org.eclipse.jetty:jetty-xml:jar:8.1.14.v20131031:provided
[INFO] |  |  |  |  \- org.eclipse.jetty:jetty-servlet:jar:8.1.14.v20131031:provided
[INFO] |  |  |  \- org.eclipse.jetty:jetty-jndi:jar:8.1.14.v20131031:provided
[INFO] |  |  |     \- org.eclipse.jetty.orbit:javax.mail.glassfish:jar:1.4.1.v201005082020:provided
[INFO] |  |  |        \- org.eclipse.jetty.orbit:javax.activation:jar:1.1.0.v201105071233:provided
[INFO] |  |  +- org.eclipse.jetty:jetty-security:jar:8.1.14.v20131031:provided
[INFO] |  |  +- org.eclipse.jetty:jetty-util:jar:8.1.14.v20131031:provided
[INFO] |  |  +- org.apache.commons:commons-lang3:jar:3.3.2:provided
[INFO] |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.5:provided
[INFO] |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.5:provided
[INFO] |  |  +- com.ning:compress-lzf:jar:1.0.0:provided
[INFO] |  |  +- net.jpountz.lz4:lz4:jar:1.2.0:provided
[INFO] |  |  +- com.twitter:chill_2.10:jar:0.3.6:provided
[INFO] |  |  |  \- com.esotericsoftware.kryo:kryo:jar:2.21:provided
[INFO] |  |  |     +- com.esotericsoftware.reflectasm:reflectasm:jar:shaded:1.07:provided
[INFO] |  |  |     +- com.esotericsoftware.minlog:minlog:jar:1.2:provided
[INFO] |  |  |     \- org.objenesis:objenesis:jar:1.2:provided
[INFO] |  |  +- com.twitter:chill-java:jar:0.3.6:provided
[INFO] |  |  +- org.spark-project.akka:akka-remote_2.10:jar:2.2.3-shaded-protobuf:provided
[INFO] |  |  |  +- org.spark-project.akka:akka-actor_2.10:jar:2.2.3-shaded-protobuf:provided
[INFO] |  |  |  |  \- com.typesafe:config:jar:1.0.2:provided
[INFO] |  |  |  +- org.spark-project.protobuf:protobuf-java:jar:2.4.1-shaded:provided
[INFO] |  |  |  \- org.uncommons.maths:uncommons-maths:jar:1.2.2a:provided
[INFO] |  |  +- org.spark-project.akka:akka-slf4j_2.10:jar:2.2.3-shaded-protobuf:provided
[INFO] |  |  +- org.json4s:json4s-jackson_2.10:jar:3.2.10:provided
[INFO] |  |  |  \- org.json4s:json4s-core_2.10:jar:3.2.10:provided
[INFO] |  |  |     +- org.json4s:json4s-ast_2.10:jar:3.2.10:provided
[INFO] |  |  |     \- org.scala-lang:scalap:jar:2.10.0:provided
[INFO] |  |  |        \- org.scala-lang:scala-compiler:jar:2.10.0:provided
[INFO] |  |  |           \- org.scala-lang:scala-reflect:jar:2.10.0:provided
[INFO] |  |  +- colt:colt:jar:1.2.0:provided
[INFO] |  |  |  \- concurrent:concurrent:jar:1.3.4:provided
[INFO] |  |  +- org.apache.mesos:mesos:jar:shaded-protobuf:0.18.1:provided
[INFO] |  |  +- io.netty:netty-all:jar:4.0.23.Final:provided
[INFO] |  |  +- com.clearspring.analytics:stream:jar:2.7.0:provided
[INFO] |  |  +- com.codahale.metrics:metrics-core:jar:3.0.0:provided
[INFO] |  |  +- com.codahale.metrics:metrics-jvm:jar:3.0.0:provided
[INFO] |  |  +- com.codahale.metrics:metrics-json:jar:3.0.0:provided
[INFO] |  |  +- com.codahale.metrics:metrics-graphite:jar:3.0.0:provided
[INFO] |  |  +- org.tachyonproject:tachyon-client:jar:0.5.0:provided
[INFO] |  |  |  \- org.tachyonproject:tachyon:jar:0.5.0:provided
[INFO] |  |  +- org.spark-project:pyrolite:jar:2.0.1:provided
[INFO] |  |  \- net.sf.py4j:py4j:jar:0.8.2.1:provided
[INFO] |  +- org.eclipse.jetty:jetty-server:jar:8.1.14.v20131031:provided
[INFO] |  |  +- org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:provided
[INFO] |  |  +- org.eclipse.jetty:jetty-continuation:jar:8.1.14.v20131031:provided
[INFO] |  |  \- org.eclipse.jetty:jetty-http:jar:8.1.14.v20131031:provided
[INFO] |  |     \- org.eclipse.jetty:jetty-io:jar:8.1.14.v20131031:provided
[INFO] |  \- org.scala-lang:scala-library:jar:2.10.4:provided
[INFO] +- com.sun.jersey:jersey-core:jar:1.9.1:compile
[INFO] +- org.apache.hadoop:hadoop-client:jar:2.4.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-hdfs:jar:2.4.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-mapreduce-client-app:jar:2.4.0:compile
[INFO] |  |  +- org.apache.hadoop:hadoop-mapreduce-client-common:jar:2.4.0:compile
[INFO] |  |  |  +- org.apache.hadoop:hadoop-yarn-client:jar:2.4.0:compile
[INFO] |  |  |  |  \- com.sun.jersey:jersey-client:jar:1.9:compile
[INFO] |  |  |  \- org.apache.hadoop:hadoop-yarn-server-common:jar:2.4.0:compile
[INFO] |  |  \- org.apache.hadoop:hadoop-mapreduce-client-shuffle:jar:2.4.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-yarn-api:jar:2.4.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-mapreduce-client-jobclient:jar:2.4.0:compile
[INFO] |  \- org.apache.hadoop:hadoop-annotations:jar:2.4.0:compile
[INFO] +- com.google.guava:guava:jar:16.0:compile
[INFO] +- org.apache.hadoop:hadoop-mapreduce-client-core:jar:2.4.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-yarn-common:jar:2.4.0:compile
[INFO] |  |  +- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO] |  |  |  +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  |  |  \- javax.activation:activation:jar:1.1:compile
[INFO] |  |  +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] |  |  +- com.google.inject:guice:jar:3.0:compile
[INFO] |  |  |  +- javax.inject:javax.inject:jar:1:compile
[INFO] |  |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  \- com.sun.jersey.contribs:jersey-guice:jar:1.9:compile
[INFO] |  +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] |  +- com.google.inject.extensions:guice-servlet:jar:3.0:compile
[INFO] |  \- io.netty:netty:jar:3.6.2.Final:compile
[INFO] +- json-mapreduce:json-mapreduce:jar:1.0-SNAPSHOT:compile
[INFO] +- org.apache.avro:avro-mapred:jar:1.7.7:compile
[INFO] |  +- org.apache.avro:avro-ipc:jar:1.7.7:compile
[INFO] |  |  +- org.apache.velocity:velocity:jar:1.7:compile
[INFO] |  |  \- org.mortbay.jetty:servlet-api:jar:2.5-20081211:compile
[INFO] |  +- org.apache.avro:avro-ipc:jar:tests:1.7.7:compile
[INFO] |  +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] |  \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.apache.avro:avro:jar:1.7.7:compile
[INFO] |  +- com.thoughtworks.paranamer:paranamer:jar:2.3:compile
[INFO] |  +- org.xerial.snappy:snappy-java:jar:1.0.5:compile
[INFO] |  \- org.apache.commons:commons-compress:jar:1.4.1:compile
[INFO] |     \- org.tukaani:xz:jar:1.0:compile
[INFO] +- org.apache.hadoop:hadoop-common:jar:2.4.0:provided
[INFO] |  +- commons-cli:commons-cli:jar:1.2:compile
[INFO] |  +- org.apache.commons:commons-math3:jar:3.1.1:provided
[INFO] |  +- xmlenc:xmlenc:jar:0.52:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.4:compile
[INFO] |  +- commons-io:commons-io:jar:2.4:compile
[INFO] |  +- commons-net:commons-net:jar:3.1:provided
[INFO] |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  +- org.mortbay.jetty:jetty:jar:6.1.26:compile
[INFO] |  +- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
[INFO] |  +- com.sun.jersey:jersey-json:jar:1.9:compile
[INFO] |  |  +- org.codehaus.jettison:jettison:jar:1.1:compile
[INFO] |  |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
[INFO] |  |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.8.3:compile
[INFO] |  |  \- org.codehaus.jackson:jackson-xc:jar:1.8.3:compile
[INFO] |  +- com.sun.jersey:jersey-server:jar:1.9:compile
[INFO] |  |  \- asm:asm:jar:3.1:compile
[INFO] |  +- tomcat:jasper-compiler:jar:5.5.23:provided
[INFO] |  +- tomcat:jasper-runtime:jar:5.5.23:provided
[INFO] |  +- javax.servlet.jsp:jsp-api:jar:2.1:provided
[INFO] |  +- commons-el:commons-el:jar:1.0:provided
[INFO] |  +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  +- log4j:log4j:jar:1.2.17:compile
[INFO] |  +- net.java.dev.jets3t:jets3t:jar:0.9.0:provided
[INFO] |  |  \- com.jamesmurty.utils:java-xmlbuilder:jar:0.4:provided
[INFO] |  +- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  +- commons-configuration:commons-configuration:jar:1.6:provided
[INFO] |  |  +- commons-digester:commons-digester:jar:1.8:provided
[INFO] |  |  |  \- commons-beanutils:commons-beanutils:jar:1.7.0:provided
[INFO] |  |  \- commons-beanutils:commons-beanutils-core:jar:1.8.0:provided
[INFO] |  +- org.apache.hadoop:hadoop-auth:jar:2.4.0:provided
[INFO] |  +- com.jcraft:jsch:jar:0.1.42:provided
[INFO] |  +- com.google.code.findbugs:jsr305:jar:1.3.9:provided
[INFO] |  \- org.apache.zookeeper:zookeeper:jar:3.4.5:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.7:compile
[INFO] +- org.apache.solr:solr-solrj:jar:4.10.1:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.3.1:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.3:compile
[INFO] |  +- org.apache.httpcomponents:httpmime:jar:4.3.1:compile
[INFO] |  +- org.codehaus.woodstox:wstx-asl:jar:3.2.7:compile
[INFO] |  \- org.noggit:noggit:jar:0.5:compile
[INFO] \- com.fasterxml.jackson.core:jackson-databind:jar:2.5.0:compile
[INFO]    +- com.fasterxml.jackson.core:jackson-annotations:jar:2.5.0:compile
[INFO]    \- com.fasterxml.jackson.core:jackson-core:jar:2.5.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.327 s
[INFO] Finished at: 2015-01-28T13:12:34+01:00
[INFO] Final Memory: 17M/173M
[INFO] ------------------------------------------------------------------------

而我的 pom.xml 是:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>bigcontent</groupId>
  <artifactId>bigcontent</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>bigcontent</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <!-- put your configurations here -->
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-streaming_2.10</artifactId>
      <version>1.1.1</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-core</artifactId>
      <version>1.9.1</version>
    </dependency>

    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-client</artifactId>
      <version>2.4.0</version>
      <exclusions>
        <exclusion>
          <groupId>javax.servlet</groupId>
          <artifactId>*</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-httpclient</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>16.0</version>
    </dependency>

    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-mapreduce-client-core</artifactId>
      <version>2.4.0</version>
    </dependency>

    <dependency>
      <groupId>json-mapreduce</groupId>
      <artifactId>json-mapreduce</artifactId>
      <version>1.0-SNAPSHOT</version>
      <exclusions>
        <exclusion>
          <groupId>javax.servlet</groupId>
          <artifactId>*</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-io</groupId>
          <artifactId>*</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-lang</groupId>
          <artifactId>*</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.apache.hadoop</groupId>
          <artifactId>hadoop-common</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-httpclient</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.apache.avro</groupId>
      <artifactId>avro-mapred</artifactId>
      <version>1.7.7</version>
      <exclusions>
        <exclusion>
          <groupId>javax.servlet</groupId>
          <artifactId>*</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.apache.hadoop</groupId>
          <artifactId>hadoop-common</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-httpclient</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.avro</groupId>
      <artifactId>avro</artifactId>
      <version>1.7.7</version>
      <exclusions>
        <exclusion>
          <groupId>javax.servlet</groupId>
          <artifactId>*</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-httpclient</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-common</artifactId>
      <version>2.4.0</version>
      <scope>provided</scope>
      <exclusions>
        <exclusion>
          <groupId>javax.servlet</groupId>
          <artifactId>*</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-httpclient</groupId>
          <artifactId>*</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.google.guava</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.7.7</version>
    </dependency>

    <dependency>
      <groupId>org.apache.solr</groupId>
      <artifactId>solr-solrj</artifactId>
      <version>4.10.1</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.5.0</version>
    </dependency>

  </dependencies>
</project>

我试图在我的 pom.xml 中排除旧版本 httpclient,但无法实现我想要的。因此,作为解决方案,我降级了 SolrJ library from the latest version (4.10.3) to an older version of 4.0.0.

也许使用 Maven 的 Relocating Classes 功能可以解决这个问题,但我不想让我的 pom.xml 进一步复杂化,至少现在是这样。