SpringBoot2.x 集成Kafka 提示:java.lang.ClassNotFoundException: org.springframework.kafka.transaction.***解析

你猜 阅读:236 2021-03-31 12:46:45 评论:0

错误异常信息:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration': Unexpected exception during bean creation; nested exception is java.lang.TypeNotPresentException: Type org.springframework.kafka.transaction.KafkaAwareTransactionManager not present 
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:528) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
	at com.cloudwalk.GPApplication.main(GPApplication.java:19) [classes/:na] 
Caused by: java.lang.TypeNotPresentException: Type org.springframework.kafka.transaction.KafkaAwareTransactionManager not present 
	at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117) ~[na:1.8.0_191] 
	at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125) ~[na:1.8.0_191] 
	at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:1.8.0_191] 
	at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68) ~[na:1.8.0_191] 
	at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138) ~[na:1.8.0_191] 
	at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:1.8.0_191] 
	at sun.reflect.generics.repository.ConstructorRepository.getParameterTypes(ConstructorRepository.java:94) ~[na:1.8.0_191] 
	at java.lang.reflect.Executable.getGenericParameterTypes(Executable.java:283) ~[na:1.8.0_191] 
	at java.lang.reflect.Constructor.getGenericParameterTypes(Constructor.java:234) ~[na:1.8.0_191] 
	at org.springframework.core.MethodParameter.getGenericParameterType(MethodParameter.java:428) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.core.SerializableTypeWrapper$MethodParameterTypeProvider.getType(SerializableTypeWrapper.java:291) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.core.SerializableTypeWrapper.forTypeProvider(SerializableTypeWrapper.java:106) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.core.ResolvableType.forType(ResolvableType.java:1401) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.core.ResolvableType.forMethodParameter(ResolvableType.java:1309) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.core.ResolvableType.forMethodParameter(ResolvableType.java:1275) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.config.DependencyDescriptor.getResolvableType(DependencyDescriptor.java:316) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.GenericTypeAwareAutowireCandidateResolver.checkGenericTypeMatch(GenericTypeAwareAutowireCandidateResolver.java:77) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.GenericTypeAwareAutowireCandidateResolver.isAutowireCandidate(GenericTypeAwareAutowireCandidateResolver.java:69) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver.isAutowireCandidate(QualifierAnnotationAutowireCandidateResolver.java:147) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.isAutowireCandidate(DefaultListableBeanFactory.java:764) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.isAutowireCandidate(DefaultListableBeanFactory.java:727) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.isAutowireCandidate(DefaultListableBeanFactory.java:711) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1426) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1210) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1167) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] 
	... 14 common frames omitted 
Caused by: java.lang.ClassNotFoundException: org.springframework.kafka.transaction.KafkaAwareTransactionManager 
	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] 
	at java.lang.Class.forName0(Native Method) ~[na:1.8.0_191] 
	at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_191] 
	at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114) ~[na:1.8.0_191] 
	... 45 common frames omitted

报错pom.xml 文件依赖:

	<parent> 
		<groupId>org.springframework.boot</groupId> 
		<artifactId>spring-boot-starter-parent</artifactId> 
		<version>2.1.2.RELEASE</version> 
	</parent> 
 
    <!-- kafka 集成 --> 
	<dependency> 
		<groupId>org.springframework.kafka</groupId> 
		<artifactId>spring-kafka</artifactId> 
		<version>2.1.2.RELEASE</version> 
	</dependency>

解决

将spring-kafka依赖版本换为2.2.x即可:

   <parent> 
		<groupId>org.springframework.boot</groupId> 
		<artifactId>spring-boot-starter-parent</artifactId> 
		<version>2.1.2.RELEASE</version> 
	</parent> 
    <!-- kafka 集成 --> 
	<dependency> 
		<groupId>org.springframework.kafka</groupId> 
		<artifactId>spring-kafka</artifactId> 
		<version>2.2.9.RELEASE</version> 
	</dependency>

 

声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
排行榜
KIKK导航

KIKK导航

关注我们