2016-12-21 81 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隨每個入門者提供。

相關問題