首页 > 编程语言 > 详细

java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonNode

时间:2021-02-15 09:42:59      阅读:118      评论:0      收藏:0      [点我收藏+]

异常:

java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonNode

  at org.apache.kafka.clients.admin.NewTopic.convertToCreatableTopic(NewTopic.java:127)
  at org.apache.kafka.clients.admin.KafkaAdminClient.createTopics(KafkaAdminClient.java:1422)
  at org.apache.kafka.clients.admin.Admin.createTopics(Admin.java:127)
  at org.springframework.kafka.core.KafkaAdmin.addTopics(KafkaAdmin.java:264)
  at org.springframework.kafka.core.KafkaAdmin.addTopicsIfNeeded(KafkaAdmin.java:221)
  at org.springframework.kafka.core.KafkaAdmin.initialize(KafkaAdmin.java:189)
  at org.springframework.kafka.core.KafkaAdmin.afterSingletonsInstantiated(KafkaAdmin.java:157)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:963)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:923)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:588)
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767)
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
  at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
  at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:123)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JsonNode

  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

 

问题出现:

    @Bean
    public NewTopic topic() {
        return TopicBuilder.name("custom-kafka-1")
                .partitions(10)
                .replicas(3)
                .compact()
                .build();
    }

 

原因:

  Jackson包版本冲突导致

 

项目Springboot:2.4.2

引入spring-kafka版本:2.6.5

spring-kafka依赖的Jackson版本为 2.11.3

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.11.3</version>
      <scope>compile</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.11.3</version>
      <scope>compile</scope>
      <optional>true</optional>
    </dependency>

springboot自带依赖的Jackson版本:2.11.4

 技术分享图片

 

导致 spring-kafka 依赖的 Jackson 2.11.3版本失效,实际依赖的是2.11.4版本。

 

解决方案:

在项目中添加Jackson依赖,覆盖springboot和spring-kafka的Jackson依赖

     <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.11.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.11.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.11.3</version>
        </dependency>

 

 

END.

java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonNode

原文:https://www.cnblogs.com/yangyongjie/p/14401960.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!