spring boot+shiro中使用@RequiresRoles不生效,访问报错404

解决方案:在shiroConfig中添加以下代码:

/**
 * 开启aop注解支持
 * 即在controller中使用 @RequiresPermissions("user/userList")
 */
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager){
    AuthorizationAttributeSourceAdvisor attributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
    //设置安全管理器
    attributeSourceAdvisor.setSecurityManager(securityManager);
    return attributeSourceAdvisor;
}
@Bean
public static DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() {

    DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
    defaultAdvisorAutoProxyCreator.setUsePrefix(true);

    return defaultAdvisorAutoProxyCreator;
}

 

@RequiresRoles配置一个参数:

@RequiresRoles("公交公司")

@RequiresRoles配置多个参数:

 

@RequiresRoles(value={"公交公司","出租公司"},logical = Logical.OR)

 

你可能感兴趣的:(spring,boot,shiro)