编程语言
首页 > 编程语言> > Caused by: java.io.NotSerializableException:cn.bloghut.pojo.User

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

在这里插入图片描述

错误原因

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

解决办法

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

public class User implements Serializable 

标签:ObjectOutputStream,NotSerializableException,bloghut,sun,reflect,io,java,Method
来源: https://blog.csdn.net/qq_42025798/article/details/121716440