shiro整合redis时候因为aop的关系,在授权时候,会出现授权执行的部分server代码不走redis,而是直接进行数据库查询,这个时候,我们应该在UserReaml中,将我们所有的@Autowrite注解的service层类进行懒加载处理(具体直接加@lazy)
@Slf4j
public class UserRealm extends AuthorizingRealm {
@Autowired
@Lazy
private SysLoginService loginService;
@Autowired
@Lazy
private IRoleService roleService;
@Autowired
@Lazy
private IUserRoleService userRoleService;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
User user = ShiroUtils.getSysUser();
// 角色列表
Set<String> roles = new HashSet<String>();
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
//下一行代码就是问题所在关键
roles.add(roleService.getDataByRoleId(userRoleService.getDataByUserId(user.getUserId()).getRoleId()).getRoleKey());
info.setRoles(roles);
return info;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
......
}
这个问题困扰了我一天,一直以为是redis配置的问题,可算解决