redis序列化实体类对象报错

简述

开发时遇到redis序列化数据报错,这里记录下

错误信息

org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [cn.gov.tdt.imgonline.web.template.SessionUser]

问题定位

一般涉及到的常见的redis序列化错误的都是:

1. 序列化器替换,比如换为string serializer

2. 默认redis的序列化器,序列化的对象需要实现Serializable接口

然后这个问题关键词定位

DefaultSerializer + ‘requires a Serializable payload ’ 

所以,结论就是 实现Serializable接口

解决

sessionUser实现Serializable接口,并

private static final long serialVersionUID = ...;

你可能感兴趣的:(JAVA,redis,序列化错误)