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的自动注入下加@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 {……}
} 相关推荐
杜鲁门 2020-11-05
luckyxl0 2020-08-16
Dullonjiang 2020-08-09
xclxcl 2020-08-03
zmzmmf 2020-08-03
MicroBoy 2020-08-02
ganjing 2020-08-02
likesyour 2020-08-01
zmzmmf 2020-07-09
MicroBoy 2020-07-05
zzhao 2020-06-26
子云 2020-06-18
visionzheng 2020-06-07
neweastsun 2020-06-04
ErixHao 2020-06-03
GDreams0 2020-06-01
ganjing 2020-05-29
zmzmmf 2020-05-28
nullcy 2020-05-26