Caused by: java.io.NotSerializableException:cn.bloghut.pojo.User

错误产生环境

mybatis 项目开启二级缓存时产生

错误描述

Caused by: java.io.NotSerializableException: cn.bloghut.pojo.User
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
	at java.util.ArrayList.writeObject(ArrayList.java:762)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
	at org.apache.ibatis.cache.decorators.SerializedCache.serialize(SerializedCache.java:90)
	... 34 more

Caused by: java.io.NotSerializableException:cn.bloghut.pojo.User

错误原因

由于mybatis 缓存时要进行IO操作,所以需要实体类实现序列化接口

解决办法

让实体类实现序列化接口即可

public class User implements Serializable 
上一篇:IOC 理解二


下一篇:fromzhihutheirattention