问题描述
使用Redis缓存,读写缓存中的实体类(自己写的com.chen.app.Book类)。
一运行项目,就报错
java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [com.chen.app.Book]
解决方法
在实体类中implements Serializable,如下所示
public class Book implements Serializable {
private Integer id;
...
}
总结,要缓存的 Java 对象必须实现 Serializable 接口。