我是靠谱客的博主 受伤小馒头,最近开发中收集的这篇文章主要介绍java.lang.NoClassDefFoundError: org/apache/kafka/common/security/auth/SecurityProtocol,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

在编写kafka操作API的过程中,查询的方法都没有什么问题,删除、修改topic或者消费组的时候,会出现一大堆红色报错:

java.lang.NoClassDefFoundError: org/apache/kafka/common/security/auth/SecurityProtocol
at kafka.zk.BrokerIdZNode$.$anonfun$decode$3(ZkData.scala:213)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.immutable.Map$Map1.foreach(Map.scala:120)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at kafka.zk.BrokerIdZNode$.$anonfun$decode$2(ZkData.scala:212)
at scala.Option.map(Option.scala:146)
at kafka.zk.BrokerIdZNode$.decode(ZkData.scala:212)
at kafka.utils.ZkUtils.parseBrokerJson(ZkUtils.scala:708)
at kafka.utils.ZkUtils.$anonfun$getCluster$1(ZkUtils.scala:702)
at scala.collection.Iterator.foreach(Iterator.scala:929)
at scala.collection.Iterator.foreach$(Iterator.scala:929)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
at scala.collection.IterableLike.foreach(IterableLike.scala:71)
at scala.collection.IterableLike.foreach$(IterableLike.scala:70)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at kafka.utils.ZkUtils.getCluster(ZkUtils.scala:700)
at com.sunline.channel.kafkaAPI.manager.ConsoleApi.getCluster(ConsoleApi.java:42)
at com.sunline.channel.kafkaAPI.manager.ConsoleApiTest.getCluster(ConsoleApiTest.java:25)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.common.security.auth.SecurityProtocol
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 48 more

我的pom依赖是这样的:

<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.12</artifactId>
<version>1.1.0</version>
</dependency>
在网上各种搜,很多答案都是缺少jar包,有的说是kafka版本要换回到0.8.2.2,当然这也是一种方案,姑且可以算作方案一。
但是我的整个项目的Kafka版本使用的是最新版本,包括发送,接收消息等功能。而且全局搜索了一下,是存在这个类的,只是不在该路径下而已。那么思索一下,系统加载这个类的方法肯定不是期望版本中的,那么。。。。。。。。。。。。。
对呀,很可能是jar包冲突!!!
于是查了maven依赖的Jar包,果然有个冲突:

这里写图片描述
那么,pom依赖变成如下所示:

<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>1.1.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.12</artifactId>
<version>1.1.0</version>
</dependency>

解决冲突以后,再次执行,错误便消失了,删除修改操作轻松搞定~

如果大家有关于Spring Boot Spring Cloud等相关问题,可添加个人微信进行交流讨论,还可以关注微信公众号——青梅主码,进行更多干货获取!

个人微信号:1272808775

微信公众号~关注后,回复:java,即可获得群名片。加入java技术讨论群。

最后

以上就是受伤小馒头为你收集整理的java.lang.NoClassDefFoundError: org/apache/kafka/common/security/auth/SecurityProtocol的全部内容,希望文章能够帮你解决java.lang.NoClassDefFoundError: org/apache/kafka/common/security/auth/SecurityProtocol所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部