spring boot shiro redis整合principals.getPrimaryPrincipal()强制转换类型错误
spring boot项目使用ShiroUser shiroUser=(ShiroUser)principals.getPrimaryPrincipal() 报错错误:java.lang.ClassCastException:com.zyc.springboot.shiro.ShiroUser cannot be cast to com.zyc.springboot.shiro.ShiroU..
spring boot项目使用ShiroUser shiroUser=(ShiroUser)principals.getPrimaryPrincipal() 报错
错误:java.lang.ClassCastException:com.zyc.springboot.shiro.ShiroUser cannot be cast to com.zyc.springboot.shiro.ShiroUser
原因不太清楚,解决办法暂时发现3种:
1:有可能是spring boot 热部署造成的,去掉spring boot 热部署试一试。
2:使用org.apache.commons.beanutils.BeanUtils类进去属性转换,其实就是相当于把数据反射出来
Object key = principals.getPrimaryPrincipal();
ShiroUser shiroUser=new ShiroUser();
try {
BeanUtils.copyProperties(shiroUser, key);
} catch (Exception e) {
}
3:把当前用户的登录名信息保存进去,而不是保存一个具体的对象。
原来的代码
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(
shiroUser, user.getPassword(), this.getName());
新代码
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(
userName, user.getPassword(), this.getName());
昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链
更多推荐

所有评论(0)