记录关于在springboot中使用@RequiresRoles不起作用

今天看了shiro视频,由于视频是spring和shiro集成,我用springboot实现,遇到一些问题。最后还是百度解决了,记录一下。

就是在springboot集成shiro的时候,为了简便用了注解,问题来了,@RequiresRoles这注解不起作用。后来看了大神的解决方法,需要加入以下两个bean

@Bean
public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator() {
    DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
    advisorAutoProxyCreator.setProxyTargetClass(true);
    return advisorAutoProxyCreator;
}

@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor() {
    AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
    authorizationAttributeSourceAdvisor.setSecurityManager(securityManager());
    return authorizationAttributeSourceAdvisor;
}

 

你可能感兴趣的:(springboot)