学无先后,达者为师

网站首页 编程语言 正文

SerializationException异常产生原因及解决方案

作者:宣布无人罪 更新时间: 2023-12-18 编程语言

SerializationException异常产生原因及解决方案

01 异常发生场景

  • 当我试图取出我存入redis的数据时
@Test
void contextLoads() {
    ValueOperations valueOperations=redisTemplate.opsForValue();

    valueOperations.append("n2","666");

    System.out.println(valueOperations.get("n2"));

}
//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 java.io.StreamCorruptedException:

02 异常的产生原因

  • 通过查询语句,发现在数据库中没有出现对应的key
 keys *
  • 原来是我打错函数把append方法视为添加语句

  • 而正确的语句是

    valueOperations.set("n2","666");
    
  • 这个SerializationException算是比常见的问题了,简单来说就是无法从redis中get到数据,我犯的错是没有存,redis里没有数据当然取不到

03 解决方式

@Test
void contextLoads() {
    ValueOperations valueOperations=redisTemplate.opsForValue();

    valueOperations.set("n2","666");

    System.out.println(valueOperations.get("n2"));

}
  • 当我正确存入数据后自然就成功了

原文链接:https://blog.csdn.net/2302_77182979/article/details/134581029

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新