admin管理员组

文章数量:1654293

问题

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属性

本文标签: JavautilclassshiroRedis