[英]java.lang.NoSuchMethodError Jackson databind and Spark
I am trying to run spark-submit with Spark 1.1.0 and Jackson 2.4.4.我正在尝试使用 Spark 1.1.0 和 Jackson 2.4.4 运行 spark-submit。 I have scala code which uses Jackson to de-serialize JSON into case classes.
我有使用 Jackson 将 JSON 反序列化为 case 类的 Scala 代码。 That works just fine on its own, but when I use it with spark I get the following error:
这本身就很好用,但是当我将它与 spark 一起使用时,出现以下错误:
15/05/01 17:50:11 ERROR Executor: Exception in task 0.0 in stage 1.0 (TID 2)
java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.addField(Lcom/fasterxml/jackson/databind/introspect/AnnotatedField;Lcom/fasterxml/jackson/databind/PropertyName;ZZZ)V
at com.fasterxml.jackson.module.scala.introspect.ScalaPropertiesCollector.com$fasterxml$jackson$module$scala$introspect$ScalaPropertiesCollector$$_addField(ScalaPropertiesCollector.scala:109)
at com.fasterxml.jackson.module.scala.introspect.ScalaPropertiesCollector$$anonfun$_addFields$2$$anonfun$apply$11.apply(ScalaPropertiesCollector.scala:100)
at com.fasterxml.jackson.module.scala.introspect.ScalaPropertiesCollector$$anonfun$_addFields$2$$anonfun$apply$11.apply(ScalaPropertiesCollector.scala:99)
at scala.Option.foreach(Option.scala:236)
at com.fasterxml.jackson.module.scala.introspect.ScalaPropertiesCollector$$anonfun$_addFields$2.apply(ScalaPropertiesCollector.scala:99)
at com.fasterxml.jackson.module.scala.introspect.ScalaPropertiesCollector$$anonfun$_addFields$2.apply(ScalaPropertiesCollector.scala:93)
at scala.collection.GenTraversableViewLike$Filtered$$anonfun$foreach$4.apply(GenTraversableViewLike.scala:109)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.SeqLike$$anon$2.foreach(SeqLike.scala:635)
at scala.collection.GenTraversableViewLike$Filtered$class.foreach(GenTraversableViewLike.scala:108)
at scala.collection.SeqViewLike$$anon$5.foreach(SeqViewLike.scala:80)
at com.fasterxml.jackson.module.scala.introspect.ScalaPropertiesCollector._addFields(ScalaPropertiesCollector.scala:93)
Here is my build.sbt:这是我的 build.sbt:
//scalaVersion in ThisBuild := "2.11.4"
scalaVersion in ThisBuild := "2.10.5"
retrieveManaged := true
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
libraryDependencies ++= Seq(
"junit" % "junit" % "4.12" % "test",
"org.scalatest" %% "scalatest" % "2.2.4" % "test",
"org.mockito" % "mockito-core" % "1.9.5",
"org.specs2" %% "specs2" % "2.1.1" % "test",
"org.scalatest" %% "scalatest" % "2.2.4" % "test"
)
libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-core" % "0.20.2",
"org.apache.hbase" % "hbase" % "0.94.6"
)
//libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "1.3.0"
libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "1.1.0"
libraryDependencies += "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.4.4"
//libraryDependencies += "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.3.1"
//libraryDependencies += "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.5.0"
libraryDependencies += "com.typesafe" % "config" % "1.2.1"
resolvers += Resolver.mavenLocal
As you can see, I have tried many different versions of Jackson.如您所见,我尝试了许多不同版本的 Jackson。
Here is the shell script I use to run spark submit:这是我用来运行 spark submit 的 shell 脚本:
#!/bin/bash
sbt package
CLASS=com.org.test.spark.test.SparkTest
SPARKDIR=/Users/user/Desktop/
#SPARKVERSION=1.3.0
SPARKVERSION=1.1.0
SPARK="$SPARKDIR/spark-$SPARKVERSION/bin/spark-submit"
jar_jackson=/Users/user/scala_projects/lib_managed/bundles/com.fasterxml.jackson.module/jackson-module-scala_2.10/jackson-module-scala_2.10-2.4.4.jar
"$SPARK" \
--class "$CLASS" \
--jars $jar_jackson \
--master local[4] \
/Users/user/scala_projects/target/scala-2.10/spark_project_2.10-0.1-SNAPSHOT.jar \
print /Users/user/test.json
I use --jars
to the path of the jackson jar to the spark-submit command.我将
--jars
用于 jackson jar 到 spark-submit 命令的路径。 I have even tried different versions of Spark.我什至尝试过不同版本的 Spark。 I have also even specified the paths for the Jackson jars databind, annotations, etc but that didn't resolve the issue.
我什至还指定了 Jackson jars 数据绑定、注释等的路径,但这并没有解决问题。 Any help would be appreciated.
任何帮助,将不胜感激。 Thank you
谢谢
I had the same problem where my play-json jar was using jackson 2.3.2 and spark was using jackson 2.4.4.我有同样的问题,我的 play-json jar 使用 jackson 2.3.2 而 spark 使用 jackson 2.4.4。
While I was running the spark application, it was unable to find the method in jackson-2.3.2 and I got the same exception.当我运行 spark 应用程序时,它无法在 jackson-2.3.2 中找到该方法,并且我遇到了同样的异常。
I checked the maven dependency hierarchy for jackson.我检查了 jackson 的 maven 依赖层次结构。 It displayed the version it took and which jar (Here play used 2.3.2) and as my play-json placed at first in dependency list, it took 2.3.2 version.
它显示了它使用的版本和哪个 jar(这里 play 使用了 2.3.2),因为我的 play-json 首先放在依赖项列表中,它使用了 2.3.2 版本。
So I tried placing the play dependency at the end of the all dependencies/after the spark dependency and it worked pretty well.因此,我尝试将 play 依赖项放在所有依赖项的末尾/ spark 依赖项之后,并且效果很好。 It took 2.4.4 this time and version 2.3.2 is omitted.
这次用了2.4.4,省略了2.3.2版本。
Note that if two dependency versions are at the same depth in the dependency tree, until Maven 2.0.8 it was not defined which one would win, but since Maven 2.0.9 it's the order in the declaration that counts: the first declaration wins.
请注意,如果两个依赖版本在依赖树中处于相同的深度,则在 Maven 2.0.8 之前还没有定义哪一个会获胜,但从 Maven 2.0.9 开始,声明中的顺序很重要:第一个声明获胜。
I just ran into the same problem with jackson and spark.我刚刚在 jackson 和 spark 上遇到了同样的问题。 As I was using SBT, like user1077071, I followed the following steps:
当我使用 SBT 时,如 user1077071,我遵循以下步骤:
I did have to aplly that approach to mulatiple jackson libs though: core, annotations and databind.不过,我确实必须将这种方法应用于多个 jackson 库:核心、注释和数据绑定。 databind was the culprit, but the otehrs should be bumped as well to avoid clashes.
数据绑定是罪魁祸首,但也应该碰撞其他人以避免冲突。
After that, it worked like a charm.在那之后,它就像一个魅力。
The main reason I think is the you don't specify the right dependency.我认为的主要原因是您没有指定正确的依赖项。
If you use 3-rd party library and then submit to Spark
directly, the better way is to use sbt-assembly
( https://github.com/sbt/sbt-assembly ).如果你使用 3-rd 方库,然后直接
submit to Spark
,更好的方法是使用sbt-assembly
( https://github.com/sbt/sbt-assembly )。
得到 java.lang.NoSuchMethodError Jackson databind for method ...introspect.AnnotatedMember.annotations()
通过将jackson-databind版本2.9.0.pr3 的maven 依赖更新到2.9.1 解决了问题
I had我有
java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonStreamContext.<init>(Lcom/fasterxml/jackson/core/JsonStreamContext;)V
error when updated com.fasterxml.jackson.core libraries from 2.8.9 to 2.9.1将 com.fasterxml.jackson.core 库从 2.8.9 更新到 2.9.1 时出错
in my case, resolution is to look through gradle dependencies and in build.gradle exclude all conflicts:就我而言,解决方案是查看 gradle 依赖项并在 build.gradle 中排除所有冲突:
compile('org.springframework.boot:spring-boot-starter-web:1.5.7.RELEASE') {
exclude group: "com.fasterxml.jackson.core"
}
compile('org.springframework.boot:spring-boot-starter-jdbc:1.5.7.RELEASE') {
exclude group: "com.fasterxml.jackson.core"
}
compile('com.fasterxml.jackson.core:jackson-databind:2.9.1') {
exclude module: "jackson-annotations"
exclude module: "jackson-core"
}
compile('com.fasterxml.jackson.core:jackson-annotations:2.9.1')
compile('com.fasterxml.jackson.core:jackson-core:2.9.1')
compile 'org.scala-lang:scala-library:2.12.3'
compile('com.fasterxml.jackson.module:jackson-module-scala_2.12:2.9.1') {
exclude group: "org.scala-lang"
exclude module: "jackson-core"
exclude module: "jackson-annotations"
exclude module: "jackson-databind"
}
If you are using the latest spark version 3.0.0-preview2
, the below configuration is a working build.sbt
:如果您使用的是最新的 spark 版本
3.0.0-preview2
,以下配置是一个有效的build.sbt
:
name := "scala-streams"
version := "0.1"
scalaVersion := "2.12.10"
val sparkVersion = "3.0.0-preview2"
val playVersion="2.8.1"
val jacksonVersion="2.10.1"
//override if you wish to
//dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-core" % jacksonVersion
//dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-streaming" % sparkVersion,
"org.apache.spark" %% "spark-core" % sparkVersion,
"org.apache.spark" %% "spark-sql" % sparkVersion,
"com.typesafe.play" %% "play-json" % playVersion
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.