org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is java.io.InvalidClassException: com.xs.entity.XXX; class invalid for deserializationat org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize
在调用service 实现类时报出以上错误,原因是因为 spring会先将对象序列化,再存入redis进行缓存,而entity没有实现序列化接口,因此序列化出错,需要在对应的实体类中添加序列化即可(implements Serializable),如下:
@Override@Cacheable(value = "student")public Student getStudentById(int id) { return studentMapper.getStudentById(id);}
public class Student implements Serializable{ private int id; private String name; private String fullname;}
来源地址:https://blog.csdn.net/qq_26898033/article/details/129951400