Spring kafka 错误引起:java.lang.ClassNotFoundException: org.springframework.kafka.transaction.KafkaAwareTransactionManager

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53808053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:54:46  来源:igfitidea点击:

Spring kafka error Caused by: java.lang.ClassNotFoundException: org.springframework.kafka.transaction.KafkaAwareTransactionManager

javaspring-bootspring-kafkaspring-kafka-test

提问by Deadpool

This is wired just started spring boot project with simple main class, it works fine without spring-kafka dependency but after adding spring-kafkaand spring-kafka-testblows up with exception, github here

这是一个刚刚开始的带有简单主类的 spring boot 项目,它在没有 spring-kafka 依赖的情况下运行良好,但在添加spring-kafkaspring-kafka-test爆炸后异常,github here

gradle.build

gradle.build

apply plugin: 'java-library'

repositories {
    jcenter()
 }

dependencies {

     compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.0.RELEASE'
     compile group: 'org.springframework.kafka', name: 'spring-kafka', version: '2.0.5.RELEASE'
    testCompile group: 'org.springframework.kafka', name: 'spring-kafka-test', version: '2.0.5.RELEASE'

 }

Main class

主班

@SpringBootApplication
public class KafkaMain {

public static void main(String[] args) {
    SpringApplication.run(KafkaMain.class, args);
     }

  }

Error

错误

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-12-16 19:32:29.347 ERROR 39854 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Erro creating beanwithname'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:511) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean##代码##(AbstractBeanFactory.java:320) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.kafka.KafkaMain.main(KafkaMain.java:10) [bin/:na]
Caused by: java.lang.TypeNotPresentException: Type org.springframework.kafka.transaction.KafkaAwareTransactionManager not present

采纳答案by Artem Bilan

Spring for Apache Kafka 2.0.xis 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 start the project for Spring Boot.

Spring for Apache Kafka2.0.x与 Spring Boot 不兼容2.1.x。你必须使用Spring-Kafka 2.2.x. 仅仅依赖 Spring Boot 本身的依赖会更好。请参阅https://start.spring.io/了解如何正确启动 Spring Boot 项目的更多信息。

And please, don't duplicate your question in different places if that was not asked.

如果没有被问到,请不要在不同的地方重复你的问题。