java - 带有 Elasticsearch 的Spring Boot导致java.lang.NoSuchFieldError : IGNORE_DEPRECATIONS

标签 java spring spring-boot maven elasticsearch

我是Elastic Search的新手。开始使用Elastic搜索构建Spring Boot应用程序。

使用最新的ES版本"elasticsearch-7.7.1"并进行集成,我在使用以下maven依赖项:

    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>7.7.1</version>
    </dependency>

在我的Spring Boot应用程序中添加了以下配置:
@Configuration
public class ESConfig {

  @Bean(destroyMethod = "close")
  public RestHighLevelClient client() {
    RestHighLevelClient restHighLevelClient = new RestHighLevelClient(
        RestClient.builder(new HttpHost("localhost")));
    return restHighLevelClient;
  }

}

将以下属性添加到application.yaml
elasticsearch:
  host: localhost

在应用程序启动时获得以下异常信息:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'client' threw exception; nested exception is java.lang.NoSuchFieldError: IGNORE_DEPRECATIONS
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
    ... 19 common frames omitted
Caused by: java.lang.NoSuchFieldError: IGNORE_DEPRECATIONS
    at org.elasticsearch.client.RestHighLevelClient.<clinit>(RestHighLevelClient.java:1902)
    at com.sbs.communicationcontrol.search.config.ESConfig.client(ESConfig.java:14)

有人可以帮忙为什么发生此异常吗?

最佳答案

经过一些研发,通过添加以下两个依赖项来解决此问题:

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

        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.7.1</version>
        </dependency>

关于java - 带有 Elasticsearch 的Spring Boot导致java.lang.NoSuchFieldError : IGNORE_DEPRECATIONS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62338588/

相关文章:

java - Android 按钮不会更改它们应该编辑的文本字段

java - GridWorld 实验室问题

java - 如何确定图表面板上显示的数据量?

java - Eclipse - 对任何子字符串进行多行编辑,如 Sublime Text 和 Atom

Spring Boot + Spring Cloud Config - 如何从 Git 外部配置添加更多配置文件

java - Spring Boot Jsp 不适用于版本 2.0.2.RELEASE

spring - 如何在使用 Redis session 存储的 Spring Boot 应用程序中获取当前主体

java - SpringBoot Bean类型找不到

spring - 为公司环境设置内部Maven存储库

Java Spring Boot 配置和组件