问题描述
我正在开发一个使用 Spark 和 Java 侦听 Kafka 流的 Spark 应用程序.
I am developing a Spark application that listens to a Kafka stream using Spark and Java.
我使用 kafka_2.10-0.10.2.1.
I use kafka_2.10-0.10.2.1.
我为 Kafka 属性设置了各种参数:bootstrap.servers
、key.deserializer
、value.deserializer
等
I have set various parameters for Kafka properties: bootstrap.servers
, key.deserializer
, value.deserializer
, etc.
我的应用程序编译正常,但是当我提交它时,它失败并显示以下错误:
My application compiles fine, but when I submit it, it fails with the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/kafka/common/serialization/StringDeserializer
我确实将 StringDeserializer
用于 key.deserializer
和 value.deserializer
,所以它确实与我编写应用程序的方式有关.
I do use StringDeserializer
for key.deserializer
and value.deserializer
so it's indeed related to how I wrote my application.
pom.xml
中使用的各种maven依赖:
Various maven dependencies used in pom.xml
:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_2.10</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kafka-0-10_2.11</artifactId>
<version>2.1.1</version>
</dependency>
我已经尝试更新 Spark Streaming/kafka 的版本.我在任何地方都找不到太多东西.
I have tried updating the version of spark streaming/kafka. I could not find much anywhere.
推荐答案
这取决于 Scala 2.10
This is dependent upon Scala 2.10
您的其他依赖项使用的是 Scala 2.11
Your other dependencies are using Scala 2.11
升级版本是当前错误的正确解决方案.
Upgrading the version is the correct solution for the current error.
并确保在streaming-kafka-0-10中,这与您正在运行的Kafka版本相匹配
And make sure that within streaming-kafka-0-10, this matches the version of Kafka you're running
应用程序编译正常,但是当我尝试提交 spark 作业时,它显示错误:线程main"中的异常 java.lang.NoClassDefFoundError:
这篇关于为什么 Spark 应用程序会因“线程“main"中的“异常"而失败?java.lang.NoClassDefFoundError: ...StringDeserializer"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!