只有那些躺在坑里从不仰望高空的人,才不会|

有间猫

园龄:6年1个月粉丝:2关注:1

SpringBoot学习记录:@Cacheable不起作用 -->原因:Shiro + @Cache整合

SpringBoot学习记录:@Cacheable不起作用 -->原因:Shrio + @Cache整合

问题描述:

1、在使用shiro的项目中,整合Cache,@Cacheable失效

2、去掉ShiroConfig后,@Cacheable能够最长使用,其他注解也OK

问题原因:

@Cacheable ,当使用ehcache时,autoconfig机制会根据配置文件自动去初始化bean

而shiroConfig在@Configuration构造时,也会去初始化ehcache ,项目启动会产生如下异常

解决方法:

realm原始代码(错误):

复制代码
public class UserRealm extends AuthorizingRealm {
    @Autowired
    private AdminService adminService;
    @Autowired
    private CadreService cadreService;
    @Autowired
    private ParticipantService participantService;
    @Autowired
    private VoteService voteService;

    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {……}

    //认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {……}
}
复制代码

在realm的自动注入下加@Lazy注解,问题解决

复制代码
public class UserRealm extends AuthorizingRealm {
    @Autowired
@Lazy
private AdminService adminService; @Autowired
@Lazy
private CadreService caadreService; @Autowired
@Lazy
private ParticipantService participantService; @Autowired
@Lazy
private VoteService voteService; protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {……} //认证 @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {……} }
复制代码

 

本文作者:有间猫

本文链接:https://www.cnblogs.com/itcod/p/12555314.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   有间猫  阅读(1407)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起