要缓存的 Java 对象必须实现 Serializable 接口,因为 Spring 会将对象先序列化再存入 Redis,比如的com.defonds.bdp.city.bean.City 类,
如果不实现 Serializable 的话将会遇到类似这种错误:
nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [com.defonds.bdp.city.bean.City]]。
java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received a
最新推荐文章于 2024-08-19 03:26:55 发布
本文探讨了在Spring框架中使用Redis缓存Java对象时,对象必须实现Serializable接口的重要性。未实现该接口的对象如com.defonds.bdp.city.bean.City,在尝试缓存时将引发IllegalArgumentException异常。
484

被折叠的 条评论
为什么被折叠?



