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

Spring Boot引入Redis后Kafka事件序列化异常求助

问题:引入Redis缓存后Spring Cloud Stream向Kafka生产事件出现序列化失败

原本使用Spring Cloud Stream向Kafka生产事件功能一切正常,但引入Redis缓存后,Redis缓存功能运行正常,而向Kafka发送事件的功能出现故障,生产事件时抛出如下Redis序列化异常:

Error while producing SampleEvent: org.springframework.messaging.MessageDeliveryException: failed to send Message to channel 'sampleOutput'; 
nested exception is org.springframework.data.redis.serializer.SerializationException: Could not write JSON: Not an array: 
{"type":"record","name":"SampleEvent","namespace":"com.sample.redisandkafka","fields":[{"name":"field","type":"string","default":"null"}]} (through reference chain: org.springframework.cloud.schema.registry.ParsedSchema["schema"]->org.apache.avro.Schema$RecordSchema["elementType"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: 
Not an array: {"type":"record","name":"SampleEvent","namespace":"com.sample.redisandkafka","fields":[{"name":"field","type":"string","default":"null"}]} (through reference chain: org.springframework.cloud.schema.registry.ParsedSchema["schema"]->org.apache.avro.Schema$RecordSchema["elementType"]), failedMessage=GenericMessage [payload={"field": "value"}, headers={id=16108acf-6ca1-f1b2-2ed3-44eb857daa6b, contentType=application/*+avro, timestamp=1712741537549}]

使用版本:

  • Spring Boot 2.4.5
  • Spring Cloud Stream 2020.0.2

验证情况:移除Redis相关依赖及RedisCacheConfig类后,仅保留Kafka功能的应用可正常运行。

移除的依赖:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

移除的配置:

cache:
    cache-names: sample-cache
    default-ttl: 1 # TTL in hours
    enabled: true
    type: redis
    host: localhost
    port: 6379
    caches-ttl: # TTL in hours
      sample-cache: 1

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 07:39:52