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.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());

 

 

 

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值