springboot shiro没有注解解决方案

springboot shiro开启注释

shiroconfiguration中增加

1
2
3
4
5
6
7
@Bean
    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager) {
        AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor
            new AuthorizationAttributeSourceAdvisor();
        authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
        return authorizationAttributeSourceAdvisor;
    }

在controller中的方法前加上注解

1
@RequiresPermissions("userInfo:test")

若还没生效,应该是aop没起作用,

解决方法一

shiroconfiguration中增加

1
2
3
4
5
6
7
@Bean
    @ConditionalOnMissingBean
    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
        DefaultAdvisorAutoProxyCreator defaultAAP = new DefaultAdvisorAutoProxyCreator();
        defaultAAP.setProxyTargetClass(true);
        return defaultAAP;
    }

解决方法二

pom.xml中加入

1
2
3
4
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>

同时application.properties中补充

1
spring.aop.proxy-target-class=true
posted @ 2018-12-23 12:03  雷神约  阅读(1098)  评论(0编辑  收藏  举报