1

I am trying to configure Elastic to SpringBoot Application with Jdk 1.8 and elastic search Versi7.6.61
and Current spring version 2.2.5.RELEASE

   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.2.5.RELEASE</version>
   <relativePath/>

//these are pom for elastic search

<dependency>
      <groupId>org.elasticsearch</groupId>
      <artifactId>elasticsearch</artifactId>
      <version>${org.elasticsearch}</version>
    </dependency>

    <dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>elasticsearch-rest-high-level-client</artifactId>
      <version>${org.elasticsearch}</version>
    </dependency>
    <dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>elasticsearch-rest-client-sniffer</artifactId>
      <version>${org.elasticsearch}</version>
    </dependency>
       <dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>transport</artifactId>
      <version>${org.elasticsearch}</version>
    </dependency> 

currently, I am using the latest release of Elasticsearch version 7.6.1 I got the following the Java JDK version is 1.8 Exception

     org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchRestHighLevelClient' defined in class path resource \[org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientConfigurations$RestHighLevelClientConfiguration.class\]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class \[org.elasticsearch.client.RestHighLevelClient\] from ClassLoader \[sun.misc.Launcher$AppClassLoader@18b4aac2\]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:572) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~\[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~\[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~\[spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE\]
            at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) \[spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE\]
            at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) \[spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE\]
            at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) \[spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE\]
            at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) \[spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE\]
            at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) \[spring-boot-2.2.3.RELEASE.jar:2.2.3.RELEASE\]
            at io.dz.ReIndexing.main(ReIndexing.java:13) \[classes/:na\]
        Caused by: java.lang.IllegalStateException: Failed to introspect Class \[org.elasticsearch.client.RestHighLevelClient\] from ClassLoader \[sun.misc.Launcher$AppClassLoader@18b4aac2\]
            at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~\[spring-core-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~\[spring-core-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:232) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:210) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:149) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:310) ~\[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1094) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:569) ~\[spring-beans-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            ... 15 common frames omitted
        Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/client/Cancellable
            at java.lang.Class.getDeclaredMethods0(Native Method) ~\[na:1.8.0_161\]
            at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~\[na:1.8.0_161\]
            at java.lang.Class.getDeclaredMethods(Class.java:1975) ~\[na:1.8.0_161\]
            at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~\[spring-core-5.2.3.RELEASE.jar:5.2.3.RELEASE\]
            ... 22 common frames omitted
        Caused by: java.lang.ClassNotFoundException: org.elasticsearch.client.Cancellable
            at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~\[na:1.8.0_161\]
            at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~\[na:1.8.0_161\]
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~\[na:1.8.0_161\]
            at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~\[na:1.8.0_161\]
            ... 26 common frames omitted


//when I am trying to configure Elastic search I got the Exception class not Found 
thanks in Advance to reply][1]][1]  
5
  • Can you paste segment of your pom.xml which mentions how your have added dependency of ElasticSearch in your project Commented Mar 23, 2020 at 5:00
  • <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>${org.elasticsearch}</version> </dependency> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-high-level-client</artifactId> <version>${org.elasticsearch}</version> </dependency> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-client-sniffer</artifactId> <version>${org.elasticsearch}</version> </dependency> Commented Mar 23, 2020 at 5:05
  • @Purushottam please add the content of pom to question so that its easy to read Commented Mar 23, 2020 at 5:09
  • @OpsterESNinjaNishant I add the elastic search dependency Commented Mar 23, 2020 at 5:20
  • @Purushottam This answer might help. Commented Mar 23, 2020 at 5:57

2 Answers 2

3

The high-level REST client which you have added internally calls low-level REST client

<dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>elasticsearch-rest-high-level-client</artifactId>
      <version>${org.elasticsearch}</version>
</dependency>

This , low level client is loaded by core dependency itself, but it seems it does not correspond to version 7.x (You can check the same in your external libraries list).

In my system elastcsearch-rest-client that got added was of version 6.4.2 while I was using elastcisearch of version 7.5.0

enter image description here

So, in this case you can add dependency related to elasticsearch-rest-client manually in pom.xml by adding :

<dependency>
  <groupId> org.elasticsearch.client </ groupId>
  <artifactId> elasticsearch-rest-client </ artifactId>
  <version>${org.elasticsearch}</ version>
</ dependency>

So, your complete pom.xml related to elastic search dependencies should look like :

<dependency>
      <groupId>org.elasticsearch</groupId>
      <artifactId>elasticsearch</artifactId>
      <version>${org.elasticsearch}</version>
</dependency>

<dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>elasticsearch-rest-high-level-client</artifactId>
      <version>${org.elasticsearch}</version>
</dependency>

<dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>elasticsearch-rest-client-sniffer</artifactId>
      <version>${org.elasticsearch}</version>
</dependency>

<dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>transport</artifactId>
      <version>${org.elasticsearch}</version>
</dependency>

<dependency>
      <groupId> org.elasticsearch.client </ groupId>
      <artifactId> elasticsearch-rest-client </ artifactId>
      <version>${org.elasticsearch}</ version>
</ dependency>
Sign up to request clarification or add additional context in comments.

1 Comment

@Purushottam If your issue is resolved, can you accept the answer. Thanks.
1

When using springboot with elasticsearch, you need to be explicit with some transitive dependencies as SpringBoot declares a version 6.4...

Basically you can put this in your pom.xml:

<properties>
  <elasticsearch.version>7.6.1<elasticsearch.version>
</properties>

See documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto-customize-dependency-versions

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.