Elasticsearch: ClassNotFoundException: org.elasticsearch.plugins.ActionPlugin

Created on 28 Oct 2016  路  15Comments  路  Source: elastic/elasticsearch

I'm trying to create spring boot application with elasticsearch (without spring data).
I've added following Maven dependency:

<dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>5.0.0</version>

        </dependency>

Trying to execute the following code:

TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("http://localhost"), 9300));

and getting an exception:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client' defined in class path resource [com/receipts/parser/config/ElasticClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method 'client' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ActionPlugin
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1023)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1128)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1056)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566)
    ... 25 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method 'client' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ActionPlugin
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 37 more
Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ActionPlugin
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<clinit>(PreBuiltTransportClient.java:54)
    at com.receipts.parser.config.ElasticClientConfiguration.client(ElasticClientConfiguration.java:28)
    at com.receipts.parser.config.ElasticClientConfiguration$$EnhancerBySpringCGLIB$$b941ed2c.CGLIB$client$1(<generated>)
    at com.receipts.parser.config.ElasticClientConfiguration$$EnhancerBySpringCGLIB$$b941ed2c$$FastClassBySpringCGLIB$$ac18eb44.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
    at com.receipts.parser.config.ElasticClientConfiguration$$EnhancerBySpringCGLIB$$b941ed2c.client(<generated>)
    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:497)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 38 more
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.plugins.ActionPlugin
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 61 more

Most helpful comment

If you're using spring-boot-starter-web, just add following properties in your pom's <properties> section:

<elasticsearch.version>5.0.0</elasticsearch.version>

All 15 comments

Having the same issue. Subscribed.
here are my dependencies in case it help
dependencies { compile 'org.projectlombok:lombok:1.16.8' compile ('org.elasticsearch.client:transport:5.0.0') compile group: 'redis.clients', name: 'jedis', version: '2.9.0' compile("org.springframework.boot:spring-boot-starter-web") { exclude module: "spring-boot-starter-tomcat" } compile("org.springframework.boot:spring-boot-starter-undertow") compile("org.springframework.boot:spring-boot-starter-actuator") testCompile("junit:junit") }

I have also noticed that when listed dependencies i get this

org.elasticsearch:elasticsearch:5.0.0 -> 2.4.0

Excluding the core and importing the 5.0.0 resolved this issue but it still won't run

I suspect there is a problem somewhere in your applications classpath, the ActionPlugin class is part of the core elasticsearch-5.0.0.jar. Maybe some other component in your application is pulling another (older) version of elasticsearch? I'd suggest reopening a discussion thread in our forum at https://discuss.elastic.co/ since Elastic reserves GitHub for bug reports and feature requests. I'm closing this issue for now, please reopen if you're sure this is some real issue that we need to fix on our side.

I had the same issue. Reason was that I had lucene 5.5.0 in dependencies. Solved by upgrading lucene into version 6.2

Found that elasticsearch version is set as 2.4.0 in spring-boot-dependencies
And that is for spring-boot-starter-data-elasticsearch

If you're using spring-boot-starter-web, just add following properties in your pom's <properties> section:

<elasticsearch.version>5.0.0</elasticsearch.version>

Have the same Issue but with the Class "NetworkPlugin" - can not resolve the issue

@tademeit I had the same issue with class "NetworkPlugin". Resolved it by:

  1. Specifying elasticsearch version property in pom as @Muyv said.
  2. After step 1, I got the same error for logger class. Included Log4j dependency as mentioned here https://discuss.elastic.co/t/issue-with-elastic-search-5-0-0-noclassdeffounderror-org-apache-logging-log4j-logger/64262/2

@Muyv It's work!! 66
why?

@lanegg SpringBoot starter manages some default dependencies, which defined the default version of ElasticSearch below 5.0.0, so that there is no such class. You can explicitly define the property in your own pom to override its definition.

BTW. In m2e plugin you can use "Dependency Hierarchy" view to observe dependencies' confliction.

Any solution for this issue. Using below code.


org.elasticsearch.client
transport
5.0.0

client = new PreBuiltTransportClient(Settings.EMPTY).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host"), 9200));

Struggling this issue for long time.

same issue with spring boot but without spring data

@LimitSY Maybe you use spring boot also,
add this

<elasticsearch.version>5.0.0</elasticsearch.version>

to your pom.xml to override spring boot dependencies pom

According to Spring-boot gradle plugin doc, the ones who use gradle can add this

ext['elasticsearch.version'] = '5.0.0'

to your build.gradle.

I'm getting this with elasticsearch.version = 6.0.1

spring data version = 3.0.10.RELEASE

We are not using spring boot.

I already have
5.0.0
in my pom.xml stil getting the same error.

"Failed to instantiate [org.elasticsearch.client.Client]: Factory method 'client' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/plugins/NetworkPlugin"

any solution?

Was this page helpful?
0 / 5 - 0 ratings