整合elasticsearch-rest-high-level-client报错nested exception is java.lang.NoSuchFieldError:IGNORE_DEPREC
程序员文章站
2022-06-24 11:54:06
报错信息:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restHighLevelClient' defined in class path resource [com/whf/search/config/ElasticSearchConfig.class]: Bean instantiation via factory method failed; nested exce...
报错信息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restHighLevelClient' defined in class path resource [com/whf/search/config/ElasticSearchConfig.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.NoSuchFieldError: IGNORE_DEPRECATIONS
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.11.RELEASE.jar:5.1.11.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.11.RELEASE.jar:5.1.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.11.RELEASE.jar:5.1.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.11.RELEASE.jar:5.1.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.11.RELEASE.jar:5.1.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.11.RELEASE.jar:5.1.11.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.11.RELEASE.jar:5.1.11.RELEASE]
...........
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'restHighLevelClient' threw exception; nested exception is java.lang.NoSuchFieldError: IGNORE_DEPRECATIONS
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.11.RELEASE.jar:5.1.11.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.11.RELEASE.jar:5.1.11.RELEASE]
... 42 common frames omitted
Caused by: java.lang.NoSuchFieldError: IGNORE_DEPRECATIONS
at org.elasticsearch.client.RestHighLevelClient.<clinit>(RestHighLevelClient.java:1906) ~[elasticsearch-rest-high-level-client-7.9.3.jar:7.9.3]
at com.whf.search.config.ElasticSearchConfig.restHighLevelClient(ElasticSearchConfig.java:22) ~[classes/:na]
at com.whf.search.config.ElasticSearchConfig$$EnhancerBySpringCGLIB$$cdc49e5a.CGLIB$restHighLevelClient$0(<generated>) ~[classes/:na]
at com.whf.search.config.ElasticSearchConfig$$EnhancerBySpringCGLIB$$cdc49e5a$$FastClassBySpringCGLIB$$2f71c5f0.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.11.RELEASE.jar:5.1.11.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.11.RELEASE.jar:5.1.11.RELEASE]
..............
工程依赖:
1)SpringBoot 2.1.10
2)elasticsearch-rest-high-level-client 7.9.3
查看maven依赖发现实际引入依赖:
org.elasticsearch:elasticsearch:6.4.3
org.elasticsearch.client:elasticsearch-rest-client:6.4.3
排查:
1)进入spring-boot-starter-parent依赖
2)进入spring-boot-dependencies
3) 搜索elastic 发现SpringBoot默认的elasticsearch版本是6.4.3
解决:pom文件指定elasticsearch版本,搞定
本文地址:https://blog.csdn.net/weixin_41645232/article/details/110287188