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

Posted 闲言_

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 

以上是关于Caused by: java.io.NotSerializableException:cn.bloghut.pojo.User的主要内容,如果未能解决你的问题,请参考以下文章

Mathematical Problems Caused by CCD

Caused by SSLError

Caused by: java.lang.NoClassDefFoundError:

caused by a circular import.

异常Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationExcep

Caused by org hibernate DuplicateMappingException Duplicat