1. 问题所示
出现如下问题:
org.springframework.data.redis.serializer.SerializationException:Cannot serialize;
nested exception is org.springframework.core.serializer.support.SerializationFailedException:
Failedto serialize object using DefaultSerializer;
nested exception is java.lang.IllegalArgumentException:DefaultSetializer
requires a Serializable payload but received an object of type [org.springblade.modules.visual.dynamic.DynamicDataSource]
2. 原理分析
根据上述的逻辑提示
可以得出如下关键信息
- 在 Spring Data Redis 中,使用 Redis 作为缓存时,默认的序列化机制是通过 DefaultSerializer 来进行对象的序列化和反序列化
- DefaultSerializer 依赖于 Java 的序列化机制,而 Java 的序列化要求所有被序列化的对象必须实现 Serializable 接口
- 如果对象没有实现 Serializable 接口,就会抛出 IllegalArgumentExcept