我是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/