【发布时间】:2020-10-01 22:26:47
【问题描述】:
我是弹性搜索的新手。开始使用 Elastic search 构建 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)
谁能帮忙解释一下为什么会出现这个异常?
【问题讨论】:
-
检查您的弹性版本。必须是相同版本的驱动程序。是一样的吗?
-
@DevChauhan 已经有一段时间了,如果它对你有用,如果你能投票给答案,如果你需要更多信息,请告诉我
标签: java spring spring-boot maven elasticsearch