代码之家  ›  专栏  ›  技术社区  ›  Ryuzaki L

由以下原因导致的Spring Kafka错误:java.lang.ClassNotFoundException:org.SpringFramework.Kafka.Transaction.KafkawareTransactionManager

  •  -1
  • Ryuzaki L  · 技术社区  · 5 年前

    这是有线刚启动的SpringBoot项目,带有简单的主类,它在没有SpringKafka依赖的情况下运行良好,但是在添加 spring-kafka spring-kafka-test 除了爆炸,Github here

    建筑等级

    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'
    
     }
    

    主类

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

    误差

    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$0(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
    
    1 回复  |  直到 5 年前
        1
  •  2
  •   Artem Bilan    5 年前

    阿帕奇·卡夫卡的春天 2.0.x 与弹簧套不兼容 2.1.x .你必须使用 Spring-Kafka 2.2.x . 如果仅仅依靠SpringBoot本身的依赖性,就更好了。请看 https://start.spring.io/ 有关如何正确启动SpringBoot项目的详细信息。

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

    推荐文章