转载:https://blog.csdn.net/zengfanwei1990/article/details/79924483
stackoverflow网站上的一些文章认为,Shiro框架初始化比Spring框架的某些部件早,导致使用@Autowire注入Shiro框架的某些类不能被Spring正确初始化。
1.Shiro中会出问题的代码
public class MyShiroRealm extends AuthorizingRealm { @Resource private UserInfoService userInfoService; }
2.手动注入bean
public class MyShiroRealm extends AuthorizingRealm { //该代码仅作手动注入bean的说明,前后略有省略代码 @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0) { Long userId = ShiroUtils.getUserId(); //这里手动注入MenuService MenuService menuService = ApplicationContextRegister.getBean(MenuService.class); Set<String> perms = menuService.listPerms(userId); SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); info.setStringPermissions(perms); return info; } } 1
3.延时加载(懒加载)(推荐)
public class MyShiroRealm extends AuthorizingRealm { @Resource @Lazy private UserInfoService userInfoService; }
spring boot整合shiro后,部分注解(Cache缓存、Transaction事务等)失效的问题
原文:https://www.cnblogs.com/cq-yangzhou/p/11418117.html