shiro整合redis做缓存管理器报错class java.lang.String must has getter for field

shiro整合redis做缓存管理器的时候报错:

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()\""

这时候需要修改自定义realm,

shiro整合redis做缓存管理器报错class java.lang.String must has getter for field_第1张图片

原先这里SimpleAuthenticationInfo构造的时候传入的是username,而redis做缓存是需要key,value的,这里必须要传入user,获取id做key.

相应的授权方法中获取身份信息也要获取user

shiro整合redis做缓存管理器报错class java.lang.String must has getter for field_第2张图片 

你可能感兴趣的:(shiro,redis)