redis 反序列化deserialize异常问题解决

异常信息:

ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is org.springframework.core.NestedIOException: Failed to deserialize object type; nested exception is java.lang.ClassNotFoundException: com.xxx.tpam.dao.model.Dict] with root cause
java.lang.ClassNotFoundException: com.xxx.tpam.dao.model.Dict

分析:这个错误提示找不到类,反序列化的时候报错,而对象系列化时是跟对象所处的包路径相关的。

 我本地测试,几个系统用的同一个redis,对象在一个系统中序列化存入redis,包路径com.xxx.tpam.dao.model.Dict;主要原因是因为key也是相同,在运行另一个系统时,发现这个key已经存在了,取出时,因当前这个系统包路径为com.xxx.book.dao.model.Dict,由于两个对象的类所处的包路径不一致,反序列化失败,因而报找不到类错误。

解决方法:

直接删除redis中对应的值即可

我是使用的本地库,就直接在redis-cli 执行了flushall(删除所有数据库中的所有key ) 命令

参考:https://cloud.tencent.com/developer/article/1399860

原文地址:https://www.cnblogs.com/zouhong/p/14412973.html