java.lang.ClassNotFoundException: org.elasticsearch.common.transport.InetSocketTransportAddress

I learn es6.1 by https://www.elastic.co/guide/en/elasticsearch/client/java-api/6.1/java-docs-index.html
but test case error.
my build.gradle:

dependencies {
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.elasticsearch:elasticsearch:6.1.0'
compile 'org.elasticsearch.client:transport:6.1.0'
compile 'io.springfox:springfox-swagger2:2.7.0'
compile 'io.springfox:springfox-swagger-ui:2.7.0'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'com.google.guava:guava:23.5-jre'
runtime 'org.springframework.boot:spring-boot-devtools'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'junit:junit:4.12'
providedCompile 'org.projectlombok:lombok:1.16.18'
}

my test case

@Test
  public void createDoc() {
    ObjectMapper objectMapper = new ObjectMapper();
    TransportClient client = null;
    User user = new User();
    user.setAddress("beijingshi");
    user.setAge(28);
    user.setName("alvin");
    try {
      Settings settings = Settings.builder()
          .put("cluster.name", "my-application").build();
      client = new PreBuiltTransportClient(settings);
      IndexResponse indexResponse = client.prepareIndex("my_index", "user").setSource(user).get();
      System.out.println(indexResponse.getId());
      System.out.println(objectMapper.writeValueAsString(indexResponse.getResult()));
      System.out.println(objectMapper.writeValueAsString(indexResponse.getShardInfo()));
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      if (Objects.nonNull(client)) {
        client.close();
      }
    }

error

java.lang.NoClassDefFoundError: org/elasticsearch/common/transport/InetSocketTransportAddress

	at org.elasticsearch.transport.Netty4Plugin.getSettings(Netty4Plugin.java:55)
	at org.elasticsearch.plugins.PluginsService.lambda$getPluginSettings$0(PluginsService.java:82)
	at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
	at org.elasticsearch.plugins.PluginsService.getPluginSettings(PluginsService.java:82)
	at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:135)
	at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:262)
	at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:128)
	at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:114)
	at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:104)
	at com.alvin.es.JunitTest.createDoc(JunitTest.java:30)

I had same problem. You can easily fix it by directly adding transport-netty4-client 6.1.0 in your dependencies.

compile 'org.elasticsearch.plugin:transport-netty4-client:6.1.0'

Looks like it's some problem in dependency tree by default it's transport-netty4-client 5.5.3 in dependencies.

1 Like

It's ok. thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.