添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
大力的键盘  ·  javascript ...·  11 月前    · 
有爱心的卡布奇诺  ·  android ...·  1 年前    · 
有胆有识的槟榔  ·  3. Reference·  1 年前    · 
解决: java.lang.ClassNotFoundException: org.springframework.kafka.transaction.KafkaAwareTransactionMan 2020-04-02 16:35:32

Springboot2.1.4集成Kafka时提示ERROR:

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文件内容

<parent>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent</artifactId>
     <version>2.1.4.RELEASE</version>
     <relativePath/>
</parent>
<dependencies>
     <dependency>
          <groupId>org.springframework.kafka</groupId>
          <artifactId>spring-kafka</artifactId>
          <version>2.1.0.RELEASE</version>
     </dependency>
</dependencies>

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

<parent>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent</artifactId>
     <version>2.1.4.RELEASE</version>
     <relativePath/>
</parent>
<dependencies>
     <dependency>
          <groupId>org.springframework.kafka</groupId>
          <artifactId>spring-kafka</artifactId>
          <version>2.2.9.RELEASE</version>
     </dependency>
</dependencies>

参考:stackoverflow

Spring Boot 启动时报错如下: Java 包冲突问题 解决 : D spring .applicat ion .admin.enabled=true "- java agent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.2.3\lib\idea_rt.jar=6377:C:\Program Files\JetBrains\IntelliJ IDEA 2020.2.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Fi org . springframework .beans.factory.BeanDefinit ion StoreExcept ion : Unexpected except ion parsing XML document from file [/home/zhangjinhua/ Java / Java EE/BaiDuMessageTest/build/classes/applicat ion Context-co... Caused by: java . lan g.NoClassDefFoundError: org / springframework / tran sac t ion / Tran sac t ion Except ion at java . lan g.Class.getDeclaredConstructors0(Native Method) at... java . lan g.IllegalStateExcept ion : Failed to introspect Class [ org . springframework . boot .autoconfigure. tran sac t ion . Tran sac t ion AutoConfigurat ion ] from ClassLoader [sun.misc.Launcher$AppClassLoader@4e0e2f2a] at org . springframework .util.Reflect ion Utils.getD... 第一步:     首先可以查看一下,你的JRE使用的是不是STS默认用的路径: window--&gt;preferences-------&gt;    .......修改... spring boot 的出现最主要的原因之一就是 解决 spring 的依赖管理,减少各种依赖包的冲突,让开发者重点关注开发本身,减少环境的配置。 在 Spring Boot 没有出现之前,SSH框架整合,最开始的问题就是版本冲突,各种版本之间不兼容,让开发者苦不堪言,很长时间才能搭建出完整的一套框架。 为了 解决 该问题, Spring Boot 应运而生,当然 Spring Boot 对大部分的第三方依赖都进行了完整的测试。 不过最近发现, Spring Boot 升级太快,项目的升级速度已经无法跟上了。 <dependency> <groupId> org . springframework . kafka </groupId> <artifactId> spring - kafka </artifactId> 最近小编在学习 spring cloud的项目知识,初出茅庐,跟着视频敲,发现不对劲。视频出的时间太早了,导致和现在的 Spring Boot 版本不一样,这是个头疼的问题,一个不小心就版本不兼容。击退你的学习信心的往往不是复杂的技术和业务,而是简简单单的环境版本问题。下面跟着小编一起 解决 问题吧!! 二、报错信息(省略部分) Caused by: org . springframework .beans.BeanInstantiat ion Except ion : Failed to instantiate [ org . Spring for Apache Kafka 2.0.x is not compatible with Spring Boot 2.1.x. You have to use Spring - Kafka 2.2.x. More over would be better to just rely on the dependency from Spring Boot per se. please, see https://start. spring .io/ for more info how properly s. Spring :Caused by: java . lan g. ClassNotFoundException : org . springframework .dao.support.DaoSupport