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),如下

@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;
}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注