项目启动时加载项目中的类使用的加载器都是 
org.springframework.boot.devtools.restart.classloader.RestartClassLoader 
而从shiro session 取出来的对象(从redis中取出经过反序列化)的类加载器都是 
sun.misc.Launcher.AppClassLoader 
很明显会导致类型转换异常,原来Spring的dev-tools为了实现重新装载class自己实现了一个类加载器,来加载项目中会改变的类,方便重启时将新改动的内容更新进来。

方案一、不使用spring-boot-devtools

 

方案二:在resources目录下面创建META-INF文件夹,然后创建spring-devtools.properties

SpringBoot集成shiro-redis遇到的问题(java.lang.ClassCastException)


restart.include.mapper=/mapper-[\\w-\\.]+jar
restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar
# 因为我项目中引用了 org.crazycake:shiro-redis ,所以要引用下面这个配置
restart.include.shiro=/shiro-[\\w-\\.]+jar

好了,见证奇迹的时刻到了。

相关文章:

  • 2021-11-26
  • 2022-12-23
  • 2022-01-11
  • 2021-07-14
  • 2021-07-20
  • 2021-11-06
  • 2021-07-06
  • 2022-01-12
猜你喜欢
  • 2021-09-15
  • 2022-01-07
  • 2021-07-18
  • 2021-06-05
  • 2022-12-23
  • 2021-11-03
  • 2021-05-19
相关资源
相似解决方案