无法连接到Cassandra:java.lang.NoSuchMethodError:com.google.common.util.concurrent.Futures.withFallback

时间:2016-04-12 05:56:09

标签: java cassandra hadoop2

我正在尝试使用Java(Hadoop2)连接到cassandra,但它会抛出以下错误

Connecting to IP Address 127.0.0.1:9042...
16/04/12 10:35:13 INFO core.NettyUtil: Found Netty's native epoll     transport in the classpath, using it
Exception in thread "main" java.lang.NoSuchMethodError:    com.google.common.util.concurrent.Futures.withFallback(Lcom/google/common  /util/concurrent/ListenableFuture;Lcom/google/common/util/concurrent  /FutureFallback;Ljava/util/concurrent/Executor;)Lcom/google/common/util/concurrent/ListenableFuture;
    at com.datastax.driver.core.Connection.initAsync(Connection.java:177)
    at com.datastax.driver.core.Connection$Factory.open(Connection.java:731)
    at com.datastax.driver.core.ControlConnection.tryConnect(ControlConnection.java:251)
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:199)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:77)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1414)
    at com.datastax.driver.core.Cluster.getMetadata(Cluster.java:393)
    at cassandra.CassandraConnector.connect(CassandraConnector.java:42)
    at cassandra.Main.main(Main.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
  • 请参阅cassandra环境详情::

    • 在127.0.0.1:9042连接到测试群集。
    • [cqlsh 5.0.1 | Cassandra 2.2.5 | CQL规范3.3.1 |原生协议v4]
  • Jars我正在使用::

    • 卡桑德拉驱动器芯-3.0.0.jar
    • 番石榴19.0.jar
    • 网状-全4.1.0.CR7.jar

我尝试过其他罐子(guava> = 16.01,netty-all-4.0 ...,cassandra-driver-core-2.2.0)。但总是抛出或多或少相似的错误。

请参阅下面用于建立连接的代码段:

public void connect(final String node, final int port)

     {

        this.cluster =  Cluster.builder().addContactPoint(node).withPort(port)
            .build();

       final Metadata metadata = cluster.getMetadata();
       ProtocolVersion myCurrentVersion = cluster.getConfiguration()
            .getProtocolOptions()
            .getProtocolVersion();
       System.out.println(myCurrentVersion);

       out.printf("Connected to cluster: %s\n",  metadata.getClusterName());

       for (final Host host : metadata.getAllHosts())

          {

            out.printf("Datacenter: %s; Host: %s; Rack: %s\n",

            host.getDatacenter(), host.getAddress(), host.getRack());

          }

         session = cluster.connect();

     }

  public static void main(String[] args) {
        // TODO Auto-generated method stub

          final CassandraConnector client = new CassandraConnector();

          final String ipAddress = args.length > 0 ? args[0] : "127.0.0.1";

          final int port = args.length > 1 ? Integer.parseInt(args[1]) : 9042;

          out.println("Connecting to IP Address " + ipAddress + ":" + port + "...");

          client.connect(ipAddress, port);

          client.close();

    }

我认为可能是因为某些版本冲突,但无法找到正确的版本。 检查了一些其他类似的帖子并尝试了解决方案(使用不同的罐子),但无法解决问题 任何帮助将受到高度赞赏。

1 个答案:

答案 0 :(得分:1)

是的。你是对的。由于版本冲突,会出现此问题。 我建议你使用 guava Jar并删除其他不必要的Jars。 另请查看this answer,它可能会对您有所帮助。