org.springframework.data.Redis.serializer.SerializationException: Cannot deserialize; nested excepti
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
--结束END--
本文标题: org.springframework.data.redis.serializer.SerializationException: Cannot serialize(解决redis存入对象序列化)
本文链接: https://www.lsjlt.com/news/391468.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-01
2024-04-03
2024-04-03
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0