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

问题背景:

有多个服务

  • admin-login-service 服务(处理管理员登录)
  • redis-service 服务(提供redis操作)
  • 其他 服务

admin-login-service 服务中验证登录成功,生成 token 作为 key, 登录的 Admin 对象作为 value ,调用 redis-service 服务存储到 redis value存的是对象,不是 json 字符串)。然后在调用 其他 服务前,在拦截器中从 redis 中取出登录的 Admin 对象判断是否登录,然后报错:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is feign.FeignException: status 500 reading RedisService#get(String); content:
{"timestamp":"2020-02-03T12:02:21.835+0000","status":500,"error":"Internal Server Error","message":"Could not read JSON: Could not resolve type id 'com.cup.ycode.commons.domain.Admin' as a subtype of [simple type, class java.lang.Object]: no such class found\n at [Source: (byte[])\"[\"com.cup.ycode.commons.domain.Admin\",{\"id\":1,\"update_time\":[\"java.util.Date\",\"2020-01-24 19:11:01\"],\"create_time\":[\"java.util.Date\",\"2020-01-24 19:11:07\"],\"account\":\"yangxinhu\",\"phone\":null,\"email\":null}]\"; line: 1, column: 39]; nested exception is com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'com.cup.ycode.commons.domain.Admin' as a subtype of [simple type, class java.lang.Object]: no such class found\n at [Source: (byte[])\"[\"com.cup.ycode.commons.domain.Admin\",{\"id\":1,\"update_time\":[\"java.util.Date\",\"2020-01-24 19:11:01\"],\"create_time\":[\"java.util.Date\",\"2020-01-24 19:11:07\"],\"account\":\"yangxinhu\",\"phone\":null,\"email\":null}]\"; line: 1, column: 39]","path":"/get"}
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982) ~[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:888) ~[spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE]

报错原因:其他服务 调用 redis-service 服务,而 redis-service 服务本身没有 Admin 这个类存在,导致程序找不到要转换成的类型。

解决方法:需要将 Admin 所在的依赖加入到 redis-service 服务 与 其他 服务中,这样从 redis 中取出数据,才知道转换成什么类型。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值