问题描述

elastic search 整合spring boot ,第一个hello程序出错
报错

java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restHighLevelClient' defined in class path resource [com/bmft/hello/config/ElasticSearchConf.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

这是我的config配置类

@Configuration
public class ElasticSearchConf {
    /**
     * Register Bean,use  "@Autowired" to call this
     * @return es client .
     */
    @Bean
    RestHighLevelClient restHighLevelClient(){
        return new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("172.0.0.1", 9200, "http")));
    }

}
问题原因

在异常信息描述的:
NoSuchFieldError: IGNORE_DEPRECATIONS
(没有这个文件的错误,我们少了一些文件)

问题解决

给你的pom加上以下依赖即可(版本需要改为你自己的对应的版本)

        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>7.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.9.2</version>
        </dependency>

参考stackoverflow https://stackoverflow.com/questions/62338588/spring-boot-with-elastic-search-causing-java-lang-nosuchfielderror-ignore-depre

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐