首页 > 其他 > 详细

shiro整合redis:使用shiro-redis插件踩的坑

时间:2020-07-01 17:05:02      阅读:349      评论:0      收藏:0      [点我收藏+]

  一直想在shiro权限这块加入缓存,使用redis是再合适不过了,恰巧已经有大佬将shiro和redis整合在一起使用了,只需在引入pom文件中引入即可。

<dependency>
      <groupId>org.crazycake</groupId>
      <artifactId>shiro-redis</artifactId>
      <version>3.2.3</version>
</dependency>

但是是使用的时候,权限配置这块,也就是重写shiro的doGetAuthorizationInfo方法这里,一直进不来,完整的控制台异常信息如下:

org.crazycake.shiro.exception.PrincipalInstanceException: class com.company.project.manage.entity.UserInfo must has getter for field: id
We 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.
Default value is "id", that means your principal object has a method called "getId()"

大概意思就是UserInfo对象中必须要有id属性,并且要有对应的get方法。在身份验证的时候就已经将userinfo信息传递给了shiro,然后redis做缓存的时候需要key,key的值就与userinfo里面的id值有关。

技术分享图片

点开UserInfo对象一看,尴了个尬,主键的命名使用的是uid

技术分享图片

最后把主键换成id,就运行正常了。演示项目在我的github上面,shiro-redis插件的整合可以查看:

https://mrbird.cc/Spring-Boot-Shiro%20cache.html

shiro整合redis:使用shiro-redis插件踩的坑

原文:https://www.cnblogs.com/ruiyeclub/p/13219774.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!