SpringBoot中使用Kafka报错Error creating bean with name ‘kafkaTemplate‘ defined in class path resource
报错内容Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2022-03-01 21:10:40.729 ERROR 27988 --- [main] o.s.boot.SpringApplication: Applicat
·
报错内容
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-03-01 21:10:40.729 ERROR 27988 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaTemplate' defined in class path resource [org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.kafka.core.KafkaTemplate] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:315) ~[spring-beans-5.3.16.jar:5.3.16]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaTemplate' defined in class path resource [org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.kafka.core.KafkaTemplate] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:224) ~[spring-beans-5.3.16.jar:5.3.16]
原因
Kafka版本过低,SpringBoot版本过高,版本不匹配。
解决方案
选用合适的版本,例如:
springboot2.2.x 对应kafka2.3.x和2.4.x 版本
springboot2.3.x 对应kafka2.5.x 版本
更多推荐
已为社区贡献5条内容
所有评论(0)