scala - Elastic4S - Jackson 的 ScalaObjectMapper 类未找到并抛出 NoSuchMethodError
问题描述
我在 Scala 项目中使用 Elastic4S 时遇到问题。抛出以下错误:
java.lang.NoSuchMethodError: com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper.$init$(Lcom/fasterxml/jackson/module/scala/experimental/ScalaObjectMapper;)V
其次是 :
java.lang.NoClassDefFoundError:无法初始化类 com.sksamuel.elastic4s.json.JacksonSupport$
以下是使用的依赖项:
"com.sksamuel.elastic4s" %% "elastic4s-core" % "6.7.3",
"com.sksamuel.elastic4s" %% "elastic4s-http" % "6.7.3",
"com.github.swagger-akka-http" %% "swagger-akka-http" % "2.0.4",
"com.github.swagger-akka-http" %% "swagger-scala-module" % "2.0.5",
...
),
assemblyMergeStrategy in assembly := { _ => MergeStrategy.first }
从 Elastic4s 启动的唯一代码就是这种方法:
def testClusterUp(log: LoggingAdapter): Unit = {
val response: Response[NodeInfoResponse] = client.execute(
nodeInfo()
).await
if (response.isError) {
log.error(s"[ERROR]-[ELASTICSEARCH] $response")
throw new ExceptionInInitializerError(s"an error occurred during Elastic connector initialization : ${response.error}")
} else if (response.isSuccess) {
log.info("Cluster started successfully !")
}
}
任何帮助,将不胜感激
解决方案
似乎还有一些其他的依赖关系涵盖了这一点。例如,swagger-akka-http
使用另一个版本的 jackson-scala-module 并且如果没有在build.sbt
. 这是在这种情况下放置的配置:
("com.github.swagger-akka-http" %% "swagger-akka-http" % "2.0.4") excludeAll(ExclusionRule(organization = "com.fasterxml.jackson.module")),
("com.github.swagger-akka-http" %% "swagger-scala-module" % "2.0.5") excludeAll(ExclusionRule(organization = "com.fasterxml.jackson.module")),
在此处查看有关 sbt 依赖项排除规则的更多信息: https ://www.scala-sbt.org/release/docs/Library-Management.html#Exclude+Transitive+Dependencies
推荐阅读
- sql-server - 如何从 sql 表输出中仅删除几个值
- c - C - 如何找到norts和crosss的赢家
- javascript - 根据 Javascript 对象将复选框更改为选中
- python - 如何从python中的txt文件中删除带有重复子字符串的行?
- code-signing - 有没有办法从 java 密钥库导出 pub/priv 密钥并导入到 gpg 密钥环
- apache-pig - 如何防止Apache pig输出空文件?
- c++ - SystemC sc_signal 数组内存边界
- c# - 在自定义验证器中设置不区分大小写
- asp.net - Serenity Framework 日期时间显示在列和表单上
- http - Ionic 3 - Http 获取 401(未经授权)