You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

开发Kafka消费者未使用Jackson却报无法访问相关依赖编译错误

问题原因

你用到的org.springframework.kafka.support.serializer.JsonDeserializer底层依赖Jackson序列化框架实现POJO的JSON反序列化逻辑,其内部代码调用了Jackson核心包中的com.fasterxml.jackson.core.type.TypeReference类。你当前项目的pom依赖中未引入Jackson相关依赖,且spring-kafka、spring-boot-starter默认不会传递引入Jackson依赖,因此编译阶段会报类找不到的错误。

解决方案
  • 方式1(推荐,Spring Boot项目适配):在pom.xml的dependencies节点下添加Spring Boot官方Jackson启动器依赖,自动适配当前Spring Boot版本的Jackson兼容版本:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-json</artifactId>
</dependency>
  • 方式2(单独引入Jackson核心包):如果不需要Spring Boot封装的json相关自动配置,可单独引入Jackson核心依赖:
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
</dependency>

添加依赖后重新加载Maven依赖,重新编译项目即可解决该错误。

内容的提问来源于stack exchange,提问作者Fedor Nikolaev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 00:24:06