SpringBoot learning record: @Cacheable does not work -> The reason: Shiro + @Cache integration

SpringBoot learning record: @Cacheable does not work -> The reason: Shrio + @Cache integration

Problem Description:

1, in use shiro project, the integration of Cache, @ Cacheable failure

2, remove the ShiroConfig, @ Cacheable be able to use the longest, but also other annotations OK

problem causes:

@Cacheable, when using ehcache, autoconfig mechanism automatically according to the configuration file to initialize the bean

And when shiroConfig @Configuration construction, will go to initialize ehcache, the project will have to start following abnormal

Solution:

realm original code (error):

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

In the realm of automatic injection plus @Lezy notes, problem solving

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

 

Guess you like

Origin www.cnblogs.com/itcod/p/12555314.html