日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語言 正文

SerializationException異常產(chǎn)生原因及解決方案

作者:宣布無人罪 更新時(shí)間: 2023-12-18 編程語言

SerializationException異常產(chǎn)生原因及解決方案

01 異常發(fā)生場(chǎng)景

  • 當(dāng)我試圖取出我存入redis的數(shù)據(jù)時(shí)
@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 異常的產(chǎn)生原因

  • 通過查詢語句,發(fā)現(xiàn)在數(shù)據(jù)庫(kù)中沒有出現(xiàn)對(duì)應(yīng)的key
 keys *
  • 原來是我打錯(cuò)函數(shù)把a(bǔ)ppend方法視為添加語句

  • 而正確的語句是

    valueOperations.set("n2","666");
    
  • 這個(gè)SerializationException算是比常見的問題了,簡(jiǎn)單來說就是無法從redis中g(shù)et到數(shù)據(jù),我犯的錯(cuò)是沒有存,redis里沒有數(shù)據(jù)當(dāng)然取不到

03 解決方式

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

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

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

}
  • 當(dāng)我正確存入數(shù)據(jù)后自然就成功了

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

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新