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 deserialization
at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize
在调用service 实现类时报出以上错误,原因是因为 spring会先将对象序列化,再存入redis进行缓存,而entity没有实现序列化接口,因此序列化出错,需要在对应的实体类中添加序列化即可(implements Serializable),如下:文章来源地址https://www.toymoban.com/news/detail-629547.html
@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://www.toymoban.com/news/detail-629547.html
到了这里,关于org.springframework.data.redis.serializer.SerializationException: Cannot serialize(解决redis存入对象序列化)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!