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

解决Shiro整合Redis作为缓存管理器时的错误,需要修改自定义Realm,确保使用用户ID作为Redis的key。原文指出,在SimpleAuthenticationInfo构造时,应传入用户对象而非仅用户名,以便于获取唯一ID。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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,

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

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值