Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java客户端尝试连接到弹性搜索时出错_Java_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Netty_Guava_Guice - Fatal编程技术网 elasticsearch,netty,guava,guice,Java,elasticsearch,Netty,Guava,Guice" /> elasticsearch,netty,guava,guice,Java,elasticsearch,Netty,Guava,Guice" />

Java客户端尝试连接到弹性搜索时出错

Java客户端尝试连接到弹性搜索时出错,java,elasticsearch,netty,guava,guice,Java,elasticsearch,Netty,Guava,Guice,使用以下代码,我正在尝试连接并索引到弹性搜索: package elasticSearchTest; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import java.net.InetAddress; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.Client;

使用以下代码,我正在尝试连接并索引到弹性搜索:

package elasticSearchTest;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import java.net.InetAddress;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.testng.annotations.Test;

public class ES_Test_Class {
  @Test
  public void f() {
  try{
      Client client = TransportClient.builder().build()
               .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));


      IndexResponse response = client.prepareIndex("twitter", "tweet", "1")
                .setSource(jsonBuilder()
                            .startObject()
                                .field("user", "kimchy")
                                .field("postDate", "18/May/2011:01:48:10")
                                .field("message", "trying out Elasticsearch")
                            .endObject()
                          )
                .get();
    // Document ID (generated or not)
      String _id = response.getId();
    // Version (if it's the first time you index this document, you will get: 1)
    long _version = response.getVersion();

    System.out.println("Document id is: "+_id);

    System.out.println("Document version is: "+_version);
      }
      catch (Exception e){
          e.printStackTrace();
      }

  }
}
具有以下依赖项:

  • 列表项

然而,我不断发现以下错误:

com.google.common.util.concurrent.ExecutionError:java.lang.NoClassDefFoundError:org/jboss/netty/channel/socket/nio/WorkerPool 位于com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201) 位于com.google.common.cache.LocalCache.get(LocalCache.java:3937) 位于com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941) 位于com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824) 位于org.elasticsearch.common.inject.internal.FailableCache.get(FailableCache.java:51) 位于org.elasticsearch.common.inject.ConstructorInjectorStore.get(ConstructorInjectorStore.java:51) 位于org.elasticsearch.common.inject.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:50) 位于org.elasticsearch.common.inject.InjectorImpl.initializeBinding(InjectorImpl.java:405) 位于org.elasticsearch.common.inject.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:680)

我已经尝试过改变JAR文件的顺序和JAR的不同版本,通过前面提到的一些建议来降低和更改JAR的版本,但问题并没有得到解决

将“netty”更新为“netty-4.0.0.Alpha8”并将番石榴更新为“guava-20.0-hal”后出错:

com.google.common.util.concurrent.ExecutionError:java.lang.NoClassDefFoundError:org/jboss/netty/channel/ReceiveBufferSizePredictorFactory 位于com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2212) 位于com.google.common.cache.LocalCache.get(LocalCache.java:4054) 位于com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4058) 位于com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4985) 位于org.elasticsearch.common.inject.internal.FailableCache.get(FailableCache.java:51) 位于org.elasticsearch.common.inject.ConstructorInjectorStore.get(ConstructorInjectorStore.java:51)


我猜
WorkerPool
类自
3.5版以来就与netty混合在一起了。因此,您需要将netty版本更新到至少3.5+。

将netty更新到4+以下的版本。版本3.9之后不存在出错的类。当然,将尝试使用3.8获取更一般的注释错误NoClassDefFoundError指定在类路径中找不到相应的类。从包名中,您可以找到相关的库,在这种情况下,它显然很麻烦。通过谷歌搜索,不难发现哪些版本包含缺少的类。希望这将有助于您下次再次遇到这样的情况。