微服务中使用Redis遇到问题 Could not resolve type id ** into a subtype
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了微服务中使用Redis遇到问题 Could not resolve type id ** into a subtype,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2209字,纯文字阅读大概需要4分钟。
内容图文
![微服务中使用Redis遇到问题 Could not resolve type id ** into a subtype](/upload/InfoBanner/zyjiaocheng/878/30155d2a7659490480443da1a46def1c.jpg)
问题背景:
有多个服务
- 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 中取出数据,才知道转换成什么类型。
稳步前进的程序猿^_^ 发布了102 篇原创文章 · 获赞 26 · 访问量 7万+ 私信 关注内容总结
以上是互联网集市为您收集整理的微服务中使用Redis遇到问题 Could not resolve type id ** into a subtype全部内容,希望文章能够帮你解决微服务中使用Redis遇到问题 Could not resolve type id ** into a subtype所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。