# Unable to connect to Elasticsearch server 6.2.2 from spring application

**URL:** <https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-server-6-2-2-from-spring-application/240055>\
**Category:** Elasticsearch\
**Created:** [July 6, 2020, 7:19pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-server-6-2-2-from-spring-application/240055 "2020-07-06T19:19:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexc1](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@alexc1](https://discuss.elastic.co/u/alexc1)\
**Post date:** [July 6, 2020, 7:19pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-server-6-2-2-from-spring-application/240055/1 "2020-07-06T19:19:28Z")

</div>

Hello everyone,

I am struggling to connect my webapp based on Spring Framework 4.3.13 (not a springboot app) to an Elasticsearch server 6.2.2.

I've googling al lot but with no result unfortunally.  
Here the code I'm executing:

Maven Dependencies:

```
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-elasticsearch</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
        <version>2.1.10.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch -->
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>6.2.2</version>
    </dependency>

    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>6.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-client</artifactId>
        <version>6.2.2</version>
    </dependency>

```

The configuration Class:

```
@Configuration
@EnableElasticsearchRepositories(queryLookupStrategy = QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND,
		basePackages = "com.myapp.repositories")
public class ElasticsearchConfig {
	@Bean
	RestHighLevelClient elasticsearchClient() {
		RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(
				new HttpHost("localhost", 9200, "http")
		));
		return client;
	}
	@Bean
	ElasticsearchRestTemplate elasticsearchTemplate() {
		return new ElasticsearchRestTemplate(elasticsearchClient());
	}
}

```

The error stack:

```
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchProductsServiceImpl': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchProductRepository': Cannot resolve reference to bean 'elasticsearchTemplate' while setting bean property 'elasticsearchOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchTemplate' defined in com.alex.myapp.config.ElasticsearchConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate]: Factory method 'elasticsearchTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchClient' defined in com.alex.myapp.config.ElasticsearchConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/action/main/MainRequest
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
	..............
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
	.....
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchProductRepository': Cannot resolve reference to bean 'elasticsearchTemplate' while setting bean property 'elasticsearchOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchTemplate' defined in com.alex.myapp.config.ElasticsearchConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate]: Factory method 'elasticsearchTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchClient' defined in com.alex.myapp.config.ElasticsearchConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/action/main/MainRequest
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
	....org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
	... 60 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchTemplate' defined in com.alex.myapp.config.ElasticsearchConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate]: Factory method 'elasticsearchTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchClient' defined in com.alex.myapp.config.ElasticsearchConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/action/main/MainRequest
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
....
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
	... 73 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate]: Factory method 'elasticsearchTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchClient' defined in com.alex.myapp.config.ElasticsearchConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'elasticsearchClient' 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:588)
	... 82 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchClient' defined in com.alex.myapp.config.ElasticsearchConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/action/main/MainRequest
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
	.....
	at com.alex.myapp.config.ElasticsearchConfig$$EnhancerBySpringCGLIB$$cc557832.elasticsearchTemplate(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
	... 83 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/action/main/MainRequest
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	....
	... 106 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.action.main.MainRequest
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1358)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180)
	... 117 common frames omitted

```

Can anyone give me a hint please?  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 7, 2020, 12:07pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-server-6-2-2-from-spring-application/240055/2 "2020-07-07T12:07:12Z")

</div>

Look at the Spring Data Elasticsearch documentation: [https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#preface.metadata](https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#preface.metadata)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/9/895fc82a14ee486d618489462ede9ac6ad063048.png)

You should probably use here Spring Data Elasticsearch 3.1.x or upgrade all which could be even better.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 4, 2020, 12:07pm UTC](https://discuss.elastic.co/t/unable-to-connect-to-elasticsearch-server-6-2-2-from-spring-application/240055/3 "2020-08-04T12:07:13Z")

</div>

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