问题
shiro与redis整合时出现如下异常,这个大概是说缺少id或者authCacheKey 字段属性
class java.lang.String must has getter for field: authCacheKey or id\nWe need a
field to identify this Cache Object in Redis. So you need to defined an id field
which you can get unique id to identify this principal. For example, if you use
UserInfo as Principal class, the id field maybe userId, userName, email, etc. For
example, getUserId(), getUserName(), getEmail(), etc.\nDefault value is
authCacheKey or id, that means your principal object has a method called
\"getAuthCacheKey()\" or \"getId()\""
原因
这个问题出现的原因之一是我们在进行doGetAuthenticationInfo 用户认证时,new SimpleAuthenticationInfo(User,pwd,this.getClass().getName());这里传递的User实体对象中,没有id或者authCacheKey 属性,根据异常描述,可能有userId, userName, email, etc.这些属性也行,我解决的方案是加id属性就没有出错了
解决方法
new SimpleAuthenticationInfo(User,pwd,this.getClass().getName())传入的user实体中加上id属性
本文解析了在Shiro与Redis整合时遇到的异常,该异常源于User实体对象缺乏id或authCacheKey属性,导致无法在Redis中唯一标识Cache对象。通过在User实体中增加id属性,解决了此问题。

450

被折叠的 条评论
为什么被折叠?



