我在我的应用中使用play 2.6
和scala 2.12
,使用elastic4s进行弹性搜索。
在我的build.sbt
:
"com.sksamuel.elastic4s" %% "elastic4s-core" % "5.6.0",
"com.sksamuel.elastic4s" %% "elastic4s-http" % "5.6.0",
我在日志中不断收到此异常:
Exception in thread "I/O dispatcher 16" java.lang.NoClassDefFoundError: Could not initialize class com.sksamuel.elastic4s.http.JacksonSupport$
at com.sksamuel.elastic4s.http.ResponseHandler$.fromEntity(ResponseHandler.scala:47)
at com.sksamuel.elastic4s.http.DefaultResponseHandler.$anonfun$onResponse$1(ResponseHandler.scala:55)
at scala.util.Try$.apply(Try.scala:209)
at com.sksamuel.elastic4s.http.DefaultResponseHandler.onResponse(ResponseHandler.scala:55)
at com.sksamuel.elastic4s.http.HttpExecutable$RichRestClient$$anon$1.onSuccess(HttpExecutable.scala:27)
at org.elasticsearch.client.RestClient$FailureTrackingResponseListener.onSuccess(RestClient.java:597)
at org.elasticsearch.client.RestClient$1.completed(RestClient.java:352)
at org.elasticsearch.client.RestClient$1.completed(RestClient.java:343)
at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:119)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:177)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:436)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:326)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588)
at java.lang.Thread.run(Thread.java:748)
试图找出可能导致这种情况的原因。
在另一个日志中也看到了:
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.8.8 requires Jackson Databind version >= 2.8.0 and < 2.9.0
所以它看起来像杰克逊版本,或者与杰克逊版本,但不知道我在哪里更新它或它在哪里失败...
有人遇到过这个问题吗? 谢谢!
答案 0 :(得分:2)
仔细检查您是否要导入elastic4s-jackson
:
libraryDependencies += "com.sksamuel.elastic4s" %% "elastic4s-jackson" % "5.6.0"
答案 1 :(得分:0)
我在使用 jackson 模块时也遇到了与 play 2.8 和 elastic4s 6.7.3 完全相同的问题
帮助我的是运行 evicted
并查看每个库的依赖项并找出它为什么无法加载该特定类。最终升级到 6.7.8 最终解决了这个问题。
此外,如果您查看 elasic4s 项目的 buid.sbt 文件,它会列出它使用的所有版本 https://github.com/sksamuel/elastic4s/blob/master/build.sbt
答案 2 :(得分:0)
您可以使用 jackson-module-scala 并排除在 elastic4s-http 中引用的 com.fasterxml.jackson 并验证 com.fasterxml.jackson 在应用程序运行时在库/类路径中是否可用。