Errors when using spring-data-elasticsearch version 3.0.0.BUILD-SNAPSHOT and Elasticsearch 5.4.0

I am trying to use Spring Data with Elasticsearch 5.4.0, but it seems like I cannot get it to work. I had a similar configuration that worked with ES 2.4.5, but it fails when I try to upgrade.

I cannot seem to get it working, and after days of trying to figure this out, I believe there may be something inherently wrong with the Spring Data elasticsearch library. I have also created a throwaway Python project trying to connect to my ES instance and that works fine.

I don't have enough characters available for the full stacktrace, but here is the error at the bottom:

Caused by: java.lang.NoClassDefFoundError: org/springframework/data/mapping/model/Property
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_111]
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_111]
	at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_111]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:489) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:206) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:187) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:125) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:295) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:992) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	... 72 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.data.mapping.model.Property
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_111]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_111]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_111]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_111]
	... 83 common frames omitted

The Maven pom.xml file is largely:

<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
		<elasticsearch.version>5.4.0</elasticsearch.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>com.rabbitmq</groupId>
			<artifactId>amqp-client</artifactId>
			<version>4.0.2</version>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>com.google.cloud</groupId>
			<artifactId>google-cloud-storage</artifactId>
			<version>1.0.2</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-elasticsearch</artifactId>
			<version>3.0.0.BUILD-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-api</artifactId>
			<version>2.8.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-core</artifactId>
			<version>2.8.2</version>
		</dependency>
	</dependencies>

Spring configurations file:

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.es.backend.repository")
public class EsConfig {

    @Value("${elasticsearch.host}")
    private String elasticsearchHost;

    @Value("${elasticsearch.port}")
    private int elasticsearchPort;

    @Value("${elasticsearch.cluster_name}")
    private String elasticsearchClusterName;

    @Bean
    public Client client() throws Exception {

        Settings esSettings = Settings.builder()
                .put("cluster.name", elasticsearchClusterName)
                .build();

        return new PreBuiltTransportClient(esSettings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(elasticsearchHost), elasticsearchPort));
    }

    @Bean
    public ElasticsearchOperations elasticsearchTemplate() throws Exception {
        return new ElasticsearchTemplate(client());
    }

}
1 Like

IMO it's a spring question.

org.springframework.data.mapping.model.Property is missing in your classpath apparently.

Note that I don't know if spring-data-elasticsearch has been updated to elasticsearch 5.

Thanks for the reply, David!

As far as I can tell from the spring-data-elasticsearch Github page, it has been updated to ES 5.x.x.

As for this being a Spring question, it's my fault that I did not include a larger chunk of the stacktrace. Here's a slightly larger piece of it. The error is coming from elasticsearchTemplate, so that would be something internal in the elasticsearch libraries.

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/mapping/model/Property
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:526) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	... 38 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/data/mapping/model/Property
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_111]
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_111]
	at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_111]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:489) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:206) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:187) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:125) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:295) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:992) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	... 72 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.data.mapping.model.Property
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_111]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_111]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_111]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_111]
	... 83 common frames omitted

There are some examples of how to work with spring-data-elasticsearch on Github, but they are all 2-3 years old and none of them cover 5.x.x. If there is any chance that someone from the team, or anyone really, could provide a very simple example of how this is supposed to work, that would be awesome.

1 Like

I don't see anything in the stacktrace related to org.elasticsearch. Do I miss something?

Sorry it took some time to respond, I've been away.

You are correct, there is no direct reference to org.elasticsearch anywhere in the stacktrace. However, there seems to be a problem with the Elasticsearch Spring Data package, albeit on the Spring side of things. The only thing I can think of is that the Spring Data dependencies in the spring-data-elasticsearch@3.0.0.BUILD-SNAPSHOT package are not the correct ones.

I have created a very small, bare-bones Github repo that reproduces the problem - https://github.com/CGavrila/spring-data-elasticsearch. There is also a full stacktrace in the repo's README.

It is also possible that I am doing something wrong in my Entity, but there really doesn't seem to be any documentation out there containing hints as to what might be wrong.

I know you don't have time to look at every single problem, but in this case, it looks like a genuine problem with the Spring integration.

1 Like

I'm afraid I don't have the answer. To me it's more something you should ask on the spring data mailing list.

BTW you are not alone:

I'm planning to play around Spring Data ES integration this summer but for now I have little experience with it (well almost no experience).

Anyway, thanks a lot for the full repository example. I know it's a lot of efforts doing so.

Yeah, no worries, I realize you can't just spend time helping everyone individually, so no worries. I've just settled for ES 2.4.x for the moment, will retry with 5.x.x when I get this fixed somehow.

Thanks for the help!

yeah i used to meet the same question as u, but i remove the spring-data then it works.just use transport api is better

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