title: NoClassDefFoundError error creating RestHighLevelClient bean
body: <p>I'm getting an error creating a HighEndRestClient bean in a SpringBoot app.  I have done a test 'app' where I checked I can instantiate the objects I want and then make the calls I want to and I am now making baby steps into making a new application.</p>
  
  <p>I have these dependencies in the pom </p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.elasticsearch.client&lt;/groupId&gt;
          &lt;artifactId&gt;elasticsearch-rest-client&lt;/artifactId&gt;
          &lt;version&gt;5.6.3&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.elasticsearch.client&lt;/groupId&gt;
          &lt;artifactId&gt;elasticsearch-rest-high-level-client&lt;/artifactId&gt;
          &lt;version&gt;5.6.3&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>and I have written this very basic code in a configuration class which doesn't do much yet </p>
  
  <pre><code>@Configuration
  @PropertySource(value = "classpath:application.properties")
  @EnableElasticsearchRepositories(basePackages = "com.indexbuilder.es.repo")
  public class ElasticsearchConfiguration {
      @Value("${elasticsearch.host}")
      private String EsHost;
  
      @Value("${elasticsearch.port}")
      private int EsPort;
  
      @Value("${elasticsearch.clustername}")
      private String EsClusterName;
  
  
      @Bean
      public RestClientBuilder coreBuilder() throws Exception {
          RestClientBuilder builder = RestClient.builder(new HttpHost("localhost", 9200, "http"));
          builder.setMaxRetryTimeoutMillis(10000);
  
          builder.setFailureListener(new RestClient.FailureListener() {
              @Override
              public void onFailure(HttpHost host) {
                  System.out.println("FAILURE !!!! FailureListener HAS WOKEN UP!!!! CREATYE A FAILURE LISTENER BEAN" );
              }
          });
  
          return builder;
        }
  
      @Bean
      public RestClient restLowLevelClient() throws Exception{
          RestClient restClient = coreBuilder().build();
          return restClient;
      }
  </code></pre>
  
  <p>This works fine as far as I can see (I haven't done much with it yet...)</p>
  
  <p>when I add this (initially I was passing in the RestClient bean but now I'm temporarily creating a local object for more clarity)</p>
  
  <pre><code>    @Bean
      public RestHighLevelClient restHighLevelClient() throws Exception{
          RestClient restClient = coreBuilder().build();
          RestHighLevelClient client = new RestHighLevelClient(restClient);
          return client;
      }
  </code></pre>
  
  <p>I get this java.lang.NoClassDefFoundError error </p>
  
  <blockquote>
    <p>=========|_|==============|___/=/<em>/</em>/_/  :: Spring Boot ::        (v1.5.1.RELEASE)</p>
    
    <p>[WARNING]  java.lang.reflect.InvocationTargetException    at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)     at
    org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:527)
      at java.lang.Thread.run(Thread.java:745) Caused by:
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'restHighLevelClient' defined in class path
    resource
    [com/indexbuilder/configuration/ElasticsearchConfiguration.class]:
    Bean instantiation via factory method failed; nested exception is
    org.springframework.beans.BeanInstantiationException: Failed to
    instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory
    method 'restHighLevelClient' threw exception; nested exception is
    java.lang.NoClassDefFoundError:
    org/elasticsearch/action/main/MainRequest     at
    org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:598)
      at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1140)
      at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1034)
      at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:525)
      at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      at
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
      at
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
      at
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
      at
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:744)
      at
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
      at
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
      at
    org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
      at
    org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
      at
    org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
      at
    org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
      at
    org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
      at
    org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
      at
    com.indexbuilder.SpringBootStartUpConfig.main(SpringBootStartUpConfig.java:84)
      ... 6 more Caused by:
    org.springframework.beans.BeanInstantiationException: Failed to
    instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory
    method 'restHighLevelClient' threw exception; nested exception is
    java.lang.NoClassDefFoundError:
    org/elasticsearch/action/main/MainRequest     at
    org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
      at
    org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:587)
      ... 24 more Caused by: java.lang.NoClassDefFoundError:
    org/elasticsearch/action/main/MainRequest     at
    com.indexbuilder.configuration.ElasticsearchConfiguration.restHighLevelClient(ElasticsearchConfiguration.java:95)
      at
    com.indexbuilder.configuration.ElasticsearchConfiguration$$EnhancerBySpringCGLIB$$62f74d9a.CGLIB$restHighLevelClient$1()
      at
    com.indexbuilder.configuration.ElasticsearchConfiguration$$EnhancerBySpringCGLIB$$62f74d9a$$FastClassBySpringCGLIB$$2b29ad7b.invoke()
      at
    org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
      at
    org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
      at
    com.indexbuilder.configuration.ElasticsearchConfiguration$$EnhancerBySpringCGLIB$$62f74d9a.restHighLevelClient()
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)     at
    org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
      ... 25 more Caused by: java.lang.ClassNotFoundException:
    org.elasticsearch.action.main.MainRequest     at
    java.net.URLClassLoader.findClass(URLClassLoader.java:381)    at
    java.lang.ClassLoader.loadClass(ClassLoader.java:424)     at
    java.lang.ClassLoader.loadClass(ClassLoader.java:357)     ... 36 more</p>
  </blockquote>
  
  <p>Can anyone point me in the right direction ?</p>