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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM