码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-03-23 22:21:52      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:ice   extends   xtend   collect   也会   启动会   public   ring   ide   

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的自动注入下加@Lezy注解,问题解决

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 {……}
}

 

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

标签:ice   extends   xtend   collect   也会   启动会   public   ring   ide   

原文地址:https://www.cnblogs.com/itcod/p/12555314.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!