通过 spring-boot-starter-data-elasticsearch 查询 Elasticsearch 时出现异常

Exception while querying Elasticsearch through spring-boot-starter-data-elasticsearch

我正在使用 gradle 学习 spring-boot-starter-data-elasticsearch。 我在我的 .gradle 文件中定义了以下依赖项:

dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'org.springframework.boot:spring-boot-starter-data-elasticsearch:1.4.2.RELEASE'
compile 'org.springframework:spring-test:4.1.2.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-logging:1.4.2.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-actuator:1.4.2.RELEASE'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.6'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.6'
testCompile 'junit:junit:4.12'
}

我使用的是 Elastic search 2.3.1 版本。 我通过扩展 ElasticsearchRepository 创建了一个 class。 现在,当我尝试查询 Elasticsearch 时,我遇到了以下异常

java.lang.NoSuchMethodError: com.fasterxml.jackson.dataformat.smile.SmileGenerator.getOutputContext()Lcom/fasterxml/jackson/core/json/JsonWriteContext;`

请帮我解决这个问题。

这是一个典型的例子,您自己控制版本依赖关系,但选择了不兼容的版本。你为什么要这样做?

SpringBoot 的优势之一是它提供连贯一致的依赖管理。您不必自己指定版本,而是让特定版本的 Spring Boot 为您管理。这适用于 Maven 和 Gradle.

您可以通过前往 https://start.spring.io、select Gradle 项目并在搜索框中键入您的依赖项(web ,执行器,elasticsearch)。 Jackson 已经由网络提供,SLF4j 随每个启动器一起提供。