在打架SpringBoot+SpringCloud的架构的时候,使用到了Spring-Kafka的包。

出现了以下的错误

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.kafka.core.ProducerFactory]: Factory method 'kafkaProducerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/kafka/core/MicrometerProducerListener
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.5.jar:5.3.5]
	... 48 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/kafka/core/MicrometerProducerListener
	at org.springframework.boot.actuate.autoconfigure.metrics.KafkaMetricsAutoConfiguration.addListener(KafkaMetricsAutoConfiguration.java:71) ~[spring-boot-actuator-autoconfigure-2.4.4.jar:2.4.4]
	at org.springframework.boot.actuate.autoconfigure.metrics.KafkaMetricsAutoConfiguration.lambda$kafkaProducerMetrics$0(KafkaMetricsAutoConfiguration.java:58) ~[spring-boot-actuator-autoconfigure-2.4.4.jar:2.4.4]
	at org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration.lambda$kafkaProducerFactory$1(KafkaAutoConfiguration.java:102) ~[spring-boot-autoconfigure-2.4.4.jar:2.4.4]
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) ~[na:1.8.0_191]
	at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_191]
	at java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:390) ~[na:1.8.0_191]
	at java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:1.8.0_191]
	at java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:1.8.0_191]
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) ~[na:1.8.0_191]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_191]
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[na:1.8.0_191]
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[na:1.8.0_191]
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_191]
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) ~[na:1.8.0_191]
	at org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration.kafkaProducerFactory(KafkaAutoConfiguration.java:102) ~[spring-boot-autoconfigure-2.4.4.jar:2.4.4]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.5.jar:5.3.5]
	... 49 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.kafka.core.MicrometerProducerListener
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_191]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_191]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_191]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_191]
	... 69 common frames omitted

经过网上找到

使用的SpringBoot版本是

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.4</version>
        <relativePath/> <!-- lookup parent from repository -->
</parent>

其中配置的Spring-Kafka配置是

  <dependency>
     <groupId>org.springframework.kafka</groupId>
     <artifactId>spring-kafka</artifactId>
     <version>2.2.4</version>
 </dependency>

然后就发生了上面的错误, 查看源码是这样的

最后找到关系图,直接升级Spring-Kafka的版本

最后启动成功了。

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐