redis 反序列化异常
**当创建项目使用redis缓存时 报了“: Cannot deserialize;”这样的错误 如下面代码片段
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.gby.pojo.User
at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:84)
at org.springframework.data.redis.serializer.DefaultRedisElementReader.read(DefaultRedisElementReader.java:50)
错误分析
————首先看下错误信息 Cannot deserialize 它说不能反序列化
错误原因
———— 由于我们在添加缓存之前。 user 在之前的其他项目中使用过,并已经在redis中产生数据。所以当我们在新的项目中再次使用”user“时,会发生反序列化冲突,
@Cacheable(value="user",key="'getAll'")
解决办法
————我们只需要把redis中名为user的缓存清楚掉,重新跑一下项目就好了。