2016-12-21 126 views
0

我正在用gradle学习spring-boot-starter-data-elasticsearch。 我在下面的依赖关系定义在我.gradle文件:通过spring-boot-starter-data-elasticsearch查询Elasticsearch时出现异常

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' 
} 

我使用的2.3.1弹性搜索版本。 我通过扩展ElasticsearchRepository创建了一个类。 现在,当我尝试查询Elasticsearch我得到异常下面我

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

请帮我解决这个问题。

+0

检查并验证您的类路径中只有一个版本的杰克逊依赖项。它看起来像是类加载器加载不兼容库的典型问题。 –

回答

1

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

Spring Boot的强大之处在于它提供了连贯一致的依赖关系管理。您不要自己指定版本,而是让特定版本的Spring Boot为您管理该版本。这适用于Maven和Gradle。

您可以通过标题https://start.spring.io,选择Gradle项目并在搜索框(web,执行器,elasticsearch)中键入您的依赖关系来查看典型的gradle构建文件的外观。杰克逊已经通过网络提供,SLF4j随每个入门者提供。