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
在調(diào)用service 實(shí)現(xiàn)類(lèi)時(shí)報(bào)出以上錯(cuò)誤,原因是因?yàn)?spring會(huì)先將對(duì)象序列化,再存入redis進(jìn)行緩存,而entity沒(méi)有實(shí)現(xiàn)序列化接口,因此序列化出錯(cuò),需要在對(duì)應(yīng)的實(shí)體類(lèi)中添加序列化即可(implements Serializable),如下:文章來(lái)源地址http://www.zghlxwxcb.cn/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;
}
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-629547.html
到了這里,關(guān)于org.springframework.data.redis.serializer.SerializationException: Cannot serialize(解決redis存入對(duì)象序列化)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!