redis反序列化报错解决方案

本文详细解析了在Spring框架中使用Redis进行反序列化时遇到的ClassNotFoundException问题,并提供了具体的解决方案。通过在项目中正确引入和配置类路径,确保了跨模块数据交换的顺利进行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

redis反序列化报错解决方案

报错如下:

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.xyd.afterloan.facade.dto.info.PaymentBaseInfoDto 

项目afterloan添加了这个redis KEY,value
项目schedule获取这个key的值反序列化时,找不到com.xyd.afterloan.facade.dto.info.PaymentBaseInfoDto路径

解决方案
在schedule项目下新建com.xyd.afterloan.facade.dto.info路径,再将PaymentBaseInfoDto复制过去

redis代码如下

	@Override
	public PaymentBaseInfoDto getPaymentDto(String key) {
		PaymentBaseInfoDto result = new PaymentBaseInfoDto();  
        ValueOperations<Serializable, Object> operations = redisTemplate  
                .opsForValue();
        if(operations.get(key)==null){
        	return null;  
        }
        if("com.xyd.alchemist.biz.pojo.PaymentDto".equals(operations.get(key).getClass().getName())){
        	com.xyd.alchemist.biz.pojo.PaymentDto p = (com.xyd.alchemist.biz.pojo.PaymentDto)operations.get(key);
        	BeanUtils.copyProperties(p,result);
        }else if("com.xyd.schedule.facade.dto.info.PaymentBaseInfoDto".equals(operations.get(key).getClass().getName())){
        	result= (PaymentBaseInfoDto)operations.get(key);
        }else if("com.xyd.afterloan.facade.dto.info.PaymentBaseInfoDto".equals(operations.get(key).getClass().getName())){
            com.xyd.afterloan.facade.dto.info.PaymentBaseInfoDto p = (com.xyd.afterloan.facade.dto.info.PaymentBaseInfoDto)operations.get(key);
            BeanUtils.copyProperties(p,result);
        }
        return result;  
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值