spark 集成 kafka ,Caused by: java.lang.AbstractMethodError

首先,集群的spark版本是2.3.0

依赖:

<dependency>
    <groupId>org.apache.sparkgroupId>
    <artifactId>spark-streaming_2.11artifactId>
    <version>2.2.0version>
dependency>
<dependency>
    <groupId>org.apache.sparkgroupId>
    <artifactId>spark-streaming-kafka-0-10_2.11artifactId>
    <version>2.2.0version>
dependency>
<dependency>
    <groupId>org.apache.sparkgroupId>
    <artifactId>spark-core_2.11artifactId>
    <version>2.2.0version>
dependency>
代码:
import net.minidev.json.JSONObject
import net.minidev.json.parser.JSONParser
import org.apache.spark.SparkConf
import org.apache.spark.streaming.kafka010.{ConsumerStrategies, KafkaUtils, LocationStrategies}
import org.apache.spark.streaming.{ Seconds, StreamingContext}

object streamingFromkafka {
  val conf = new SparkConf().setAppName("test")
  val ssc = new StreamingContext(conf,Seconds(10))

  def main(args: Array[String]): Unit = {
    val kafkaParams = Map("bootstrap.servers"->"192.168.2.213:9092"
      ,("key.deserializer","org.apache.kafka.common.serialization.StringDeserializer")
      ,"value.deserializer"->"org.apache.kafka.common.serialization.StringDeserializer"
      ,"group.id"->"kafkatest"
      ,"enable.auto.commit"->"false"
    )
    val topics = Set("taobao1")
    val consumerStrategies = ConsumerStrategies.Subscribe[String,String](topics,kafkaParams)
    val kafkaDStream = KafkaUtils.createDirectStream(ssc,LocationStrategies.PreferConsistent,consumerStrategies)

    kafkaDStream.foreachRDD(rdd=> {
      val result2 = rdd.map(x => new JSONParser().parse(x.value()).asInstanceOf[JSONObject]).foreach(x=>{
        println(x)
      })
    })

    ssc.start()
    ssc.awaitTermination()
  }

}

打jar包,在standalone 的cluster 模式下运行,报错如下:
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.spark.deploy.worker.DriverWrapper$.main(DriverWrapper.scala:65)
	at org.apache.spark.deploy.worker.DriverWrapper.main(DriverWrapper.scala)
Caused by: java.lang.AbstractMethodError
	at org.apache.spark.internal.Logging$class.initializeLogIfNecessary(Logging.scala:99)
	at org.apache.spark.streaming.kafka010.KafkaUtils$.initializeLogIfNecessary(KafkaUtils.scala:39)
	at org.apache.spark.internal.Logging$class.log(Logging.scala:46)
	at org.apache.spark.streaming.kafka010.KafkaUtils$.log(KafkaUtils.scala:39)
	at org.apache.spark.internal.Logging$class.logWarning(Logging.scala:66)
	at org.apache.spark.streaming.kafka010.KafkaUtils$.logWarning(KafkaUtils.scala:39)
	at org.apache.spark.streaming.kafka010.KafkaUtils$.fixKafkaParams(KafkaUtils.scala:201)
	at org.apache.spark.streaming.kafka010.DirectKafkaInputDStream.(DirectKafkaInputDStream.scala:63)
	at org.apache.spark.streaming.kafka010.KafkaUtils$.createDirectStream(KafkaUtils.scala:147)
	at org.apache.spark.streaming.kafka010.KafkaUtils$.createDirectStream(KafkaUtils.scala:124)
	at streamingFromkafka$.main(streamingFromkafka.scala:35)
	at streamingFromkafka.main(streamingFromkafka.scala)
	... 6 more
修改方法:
    修改依赖:
       
<dependency>
    <groupId>org.apache.sparkgroupId>
    <artifactId>spark-streaming-kafka-0-10_2.11artifactId>
    <version>2.3.0version>
dependency>
重新打jar包,正常运行

你可能感兴趣的:(spark 集成 kafka ,Caused by: java.lang.AbstractMethodError)