org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restHighLevelClient' defined in class path resource [com/esdemo/config/ElasticSearchClientConfig.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/common/xcontent/DeprecationHandler
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
at com.esdemo.EsdemoApplication.main(EsdemoApplication.java:13)
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/common/xcontent/DeprecationHandler
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)
... 18 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/common/xcontent/DeprecationHandler
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.elasticsearch.client.RestHighLevelClient.<clinit>(RestHighLevelClient.java:1741)
at com.esdemo.config.ElasticSearchClientConfig.restHighLevelClient(ElasticSearchClientConfig.java:19)
at com.esdemo.config.ElasticSearchClientConfig$$EnhancerBySpringCGLIB$$cca08d.CGLIB$restHighLevelClient$0(<generated>)
at com.esdemo.config.ElasticSearchClientConfig$$EnhancerBySpringCGLIB$$cca08d$$FastClassBySpringCGLIB$$14e70886.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)
at com.esdemo.config.ElasticSearchClientConfig$$EnhancerBySpringCGLIB$$cca08d.restHighLevelClient(<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:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 19 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.common.xcontent.DeprecationHandler
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 43 common frames omitted
Process finished with exit code 1
Solution:
Check whether the jar package of ES is introduced into Maven’s POM file
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.7.0</version>
</dependency>
If there is still an error after introducing the jar package, add the following to the startup class
System.setProperty("es.set.netty.runtime.available.processors", "false");
Read More:
- [Solved] Error creating bean with name ‘configurationPropertiesBeans‘ defined in class path resource…
- [Solved] Error creating bean with name ‘redisConnectionFactory‘ defined in class path resource…
- [Solved] seata:Error creating bean with name ‘globalTransactionScanner‘ defined in class path resource
- [Solved] Springboot Error: Error creating bean with name ‘dataSource‘ defined in class path resource
- [Solved] Error creating bean with name ‘mappingJackson2HttpMessageConverter‘ defined in class path resource
- [Solved] Error creating bean with name ‘entityManagerFactory‘ defined in class path resource
- jasypt springboot Error: Error creating bean with name ‘enableEncryptablePropertySourcesPostProcessor’ defined in class path resource
- [Solved] springCloud Startup Error: Error creating bean with name ‘defaultValidator‘ defined in class path resource
- [Solved] springboot Error: Error creating bean with name ‘configurationPropertiesBeans‘ defined in class path
- Error creating bean with name ‘servletEndpointRegistrar‘ defined in class path resource
- SpringBoot Integrating elasticsearch Error: Error creating bean with name ‘restHighLevelClient‘
- [Solved] spring boot Startup Error: Error creating bean with name ‘requestMappingHandlerMapping‘ defined in class path
- [Solved] RabbitMQ Error: Error creating bean with name ‘rabbitConnectionFactory‘ defined in class path resource
- [Solved] Error creating bean with name ‘sqlSessionFactory‘ defined in class path resource
- [Solved] Error creating bean with name ‘configurationPropertiesBeans‘ defined in class path resource
- [Solved] Rabbitmq injection failed, bean creation failed, error creating bean with name ‘rabbitconnectionfactory’‘
- Springboot integration shiro error: UnsatisfiedDependencyException: Error creating bean with name ‘getShiroFilterFact
- [Solved] Error creating bean with name ’emf’ defined in org.ngrinder.infra.config.DatabaseConf
- [Solved] IDEA springboot Startup Error: java.lang.UnsatisfiedLinkError: no tcnative-1 in java.library.path
- [Solved] Springboot Error: Error creating bean with name ‘xxxController‘