Spring Cloud微服务中使用Redis遇到的问题(Could not resolve type id ** into a subtype)

背景:我们在login-service的微服务中进行登录校验,生成token做为Redis的key,把RmUserVo缓存到Redis中(没有使用JSON格式,直接使用对象),在其他的业务微服务中使用token去Redis中获取数据,转成RmUserVo类,报如下错误.

org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Could not resolve type id 'com.ftr.modules.vo.RmUserVo' into a subtype of [simple type, class java.lang.Object]: no such class found
 at [Source: [B@79ed6999; line: 1, column: 32]; nested exception is com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'com.ftr.modules.vo.RmUserVo' into a subtype of [simple type, class java.lang.Object]: no such class found at [Source: [B@79ed6999; line: 1, column: 32] at org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer.deserialize(Jackson2JsonRedisSerializer.java:73)

报错原因:业务微服务中的RmUserVo路径和login-service的微服务中的RmUserVo路径(全限定名)不同,在Redis取的数据转换类型的时候,因为接受实体类的路径不同,类型转换失败.

解决办法,业务微服务RmUserVo路径调整为和login-service的微服务一致即可.

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值