shiro @RequiresRoles 和 @RequiresPermissions 不起作用

解决方式:<aop:config proxy-target-class="true"/> 必须写在springmvc.xml中  让springmvc子容器加载。

具体配置过程:

配置使用注解进行 角色和权限的校验,要引入aspectj依赖:

<!-- 注解检验【权限】【角色】的依赖包 -->

        <dependency>

            <groupId>org.aspectj</groupId>

            <artifactId>aspectjweaver</artifactId>

            <version>1.8.9</version>

        </dependency>

springmvc.xml中配置

    <!-- 注解【权限】【角色】校验的配置 -->

    <aop:config proxy-target-class="true"/>

    <bean class="org.apache.shiro.spring.LifecycleBeanPostProcessor"></bean>

    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">

        <property name="securityManager" ref="securityManager"></property>

    </bean>

其中<aop:config proxy-target-class="true"/> 必须让springmvc子容器加载

而其中下面这部份bean配置 可以让spring加载也可以让springmvc加载,因为springmvc子容器是可以使用 父容器的对象。

<bean class="org.apache.shiro.spring.LifecycleBeanPostProcessor"></bean>

    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">

        <property name="securityManager" ref="securityManager"></property>

    </bean>

至于原因,我也没想出来,如果有哪位大佬知道的麻烦跟我说一下,谢谢。

猜你喜欢

转载自blog.csdn.net/zark721/article/details/85264362