在搞spring security的时候,发现了这么个问题:

com.liang.security.entity.user.LoginUser cannot be cast to com.liang.security.entity.user.LoginUser

顿时头皮发麻。完了,我成替身了

这个场景是我将用户给缓存到redis之后,携带token请求的时候,从redis中取到对应用户。结果呢报了这个错误。

就是反序列化时,无法转为原来对象了

报错位置:

解决方案一

不使用spring-boot-devtools热部署,这个原因呢是相关的类加载器的问题。热部署使用的类加载器和一开始启动时使用的类加载器不同,导致的问题。但是热加载不能用那可是十足的损失。

解决方案二

通过 Json 的方法转成想要的对象。

LoginUser loginUser = JSON.parseObject(JSON.toJSON(obj).toString(), LoginUser.class);

以上两种方式解决

springboot springsecurity报错 **.LoginUser cannot be cast to **.LoginUser相关推荐

  1. springboot启动报错:Unregistering JMX-exposed beans on shutdown

    环境 1,maven 3.5.0 2,eclipse 4.7.1 3,spring boot 1.5.9.RELEASE springboot启动报错 按照spring 用户手册创建新的spring ...

  2. SpringBoot启动报错:Parameter 0 of method hmset in com.qcby.rbac.util.RedisUtils required a bean of type

    SpringBoot启动报错,报错信息如下: 报错是由于A类中定义了含参数的构造函数,Spring自动构造和注入时未为该Bean传入参数,引起报错. 查了很多资料,最后发现,我是因为注释的时候没有把@ ...

  3. 【springboot】报错Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No conve

    [参考] https://www.cnblogs.com/sunupo/p/11905763.html [springboot控制台报错:] WARN 10028 - [nio-8181-exec-3 ...

  4. 启动Spring项目报错,Springboot启动报错 Disconnected from the target VM 解决过程

    启动Spring项目报错,Springboot启动报错 Disconnected from the target VM 解决过程 大概率是缺少了一下依赖 <dependency><g ...

  5. IDEA springboot启动报错java.lang.UnsatisfiedLinkError: no tcnative-1 in java.library.path

    IDEA springboot启动报错: java.lang.UnsatisfiedLinkError: no tcnative-1 in java.library.path: [D:\Java\bi ...

  6. SpringBoot启动报错Could not resolve placeholder ‘XXX.XXX‘ in value

    SpringBoot启动项目时报错: Exception encountered during context initialization - cancelling refresh attempt: ...

  7. springboot启动报错`CommandLineWrapper` is ill-suited for launching apps on Java 9+.

    项目从jdk8升级到jdk11后springboot启动报错,查询多方资料未果 报错信息: `CommandLineWrapper` is ill-suited for launching apps ...

  8. SpringBoot项目报错解决:“Error starting ApplicationContext. To display the conditions report re-run ...”

    SpringBoot项目报错:Error starting ApplicationContext. To display the conditions report re-run your appli ...

  9. Springboot运行报错BeanCreationException

    项目场景: Springboot运行报错BeanCreationException: Error creating bean with name 问题描述: BeanCreationException ...

  10. SpringBoot启动报错:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean

    SpringBoot启动报错:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean ...

最新文章

  1. Design Pattern - Prototype(C#)
  2. oracle增量合并存储过程,怎么将视图与存储过程里的逻辑合并
  3. 运行 命令 linux,Linux基本命令运行
  4. 全球及中国洗发护发市场品牌营销调研与投资竞争策略研究报告2022版
  5. Python中Numpy(2,numpy的基本操作(级联,维度转换,切分,副本))
  6. Jerry的SAP One Order框架重构的几版代码
  7. 虚拟跳线软件干什么用的_疯狂刷单!用违法软件生成虚拟手机号,“骑手”半年“刷单”牟利60余万,百米内竟有万笔订单 | 申晨间...
  8. Android 系统(119)---Android启动页黑屏及最优解决方案
  9. Django视图层:Django便捷函数,render()函数返回HttpResponse对象,redirect()函数返回HttpResponseRedirect指向传递参数的URL
  10. 购买服务器机柜需要考量的几个问题
  11. 获取android手机步数,获取手机健康应用中的步数和距离
  12. 十九个国内外主流的三维GIS软件(转)
  13. 常用的正则表达式,复制粘贴,正则就这么简单
  14. c语言合并两个顺序表算法,顺序表的两种合并操作(C语言)
  15. Python 机器人学习手册:1~5
  16. shp导入Oracle
  17. 苹果8的爆料这么多?为什么...
  18. Visual Studio 2008 项目安装和部署
  19. 【C Primer Plus】温度转换器
  20. 机器视觉的洪荒之力助中国制造2025“看”得更远

热门文章

  1. jpeg 与 png 图片格式的区别
  2. python爬虫-批量下载qq音乐
  3. 企业债和公司债的四点区别
  4. Java 可用于比较与排序的lambda表达式和comparing方法
  5. comparator 字符串比较大小_Java8 - 使用 Comparator.comparing 进行比较排序
  6. matplotlib简要画图
  7. 【免费办公软件】万彩办公大师教程丨文件批量解压工具
  8. kettle使用命令行来运行ktr和kjb
  9. 【经典】《Java170道面试笔试题全面含答案》涉及java/数据库/Spring框架/JVM/数据结构算法/设计模式相关
  10. 8本好书上新:越忙越要多读书 1