java.lang.NoSuchMethodError尝试关闭ElasticSearch客户端时出现异常

时间:2017-11-27 12:24:08

标签: java elasticsearch elasticsearch-java-api

当我尝试使用Java API 6.0关闭ElasticSearch客户端时,我在client.close()调用上遇到以下异常:

Exception in thread "elasticsearch[_client_][generic][T#1]" java.lang.NoSuchMethodError: io.netty.bootstrap.Bootstrap.config()Lio/netty/bootstrap/BootstrapConfig;
at org.elasticsearch.transport.netty4.Netty4Transport.lambda$stopInternal$7(Netty4Transport.java:390)
at org.apache.lucene.util.IOUtils.close(IOUtils.java:89)
at org.elasticsearch.common.lease.Releasables.close(Releasables.java:36)
at org.elasticsearch.common.lease.Releasables.close(Releasables.java:46)
at org.elasticsearch.common.lease.Releasables.close(Releasables.java:51)
at org.elasticsearch.transport.netty4.Netty4Transport.stopInternal(Netty4Transport.java:373)
at org.elasticsearch.transport.TcpTransport.lambda$doStop$14(TcpTransport.java:927)
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:569)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

我正在使用与用于ElasticSearch的Java API 6.0的documentation中的示例完全相同的代码:

        // on startup
    TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
            .addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));

    // on shutdown
    client.close();

2 个答案:

答案 0 :(得分:2)

NoSuchMethodError表示您的依赖项存在问题。 Java API 6.0文档指向此maven依赖项:

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>6.0.0</version>
</dependency>

上述的传递依赖是:

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-transport</artifactId>
    <version>4.1.13.Final</version>
</dependency>

在版本4.1.13.Final中,类io.netty.bootstrap.Bootstrap有一个方法config(),返回值为BootstrapConfig

public final BootstrapConfig config()
  {
    return this.config;
  }

请与mvn dependency:tree一起检查您使用的是io.netty:netty-transport的正确版本。

答案 1 :(得分:0)

在使用es 5.5.1时,我在运行测试代码时遇到了同样的问题。我通过在下面添加maven依赖来解决它:

  

   io.netty   netty-all 4.1.25.Final   测试