Shiro @RequiresRoles注解不起作用的解决办法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34873338/article/details/79483453

最近在学习SSM框架下集成Shiro,在使用Shiro注解的使用发现并不起作用,并且也在applicationContext.xml中添加了Shiro开启注解的配置。

Shiro 开启注解的配置如下:

<!--Shiro配置-->
    <!--
        1.配置lifecycleBeanPostProcessor,可以在Spring IOC容器中调用shiro的生命周期方法.
    -->
    <bean class="org.apache.shiro.spring.LifecycleBeanPostProcessor" id="lifecycleBeanPostProcessor" />

    <!--
        2.启用Spring IOC容器Shiro注解,但必须配置了lifecycleBeanPostProcessor后才可以使用
    -->
    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor" />

    <!--
        3.开启Spring AOC Shiro注解支持
    -->
    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
        <property name="securityManager" ref="securityManager"/>
    </bean>

经过一番搜索,发现了问题所在,我是在controller中使用的Shiro注解,而且我的开启注解的配置写在了Spring的配置文件下,而我的Spring配置自动扫描的时候,过滤掉使用了Controller注解的类,如下所示:

<!--自动扫描-->
    <context:component-scan base-package="com.dream" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

所以解决办法也很简单,将开启Shiro注解的配置写到SpringMVC的配置文件里即可。

猜你喜欢

转载自blog.csdn.net/qq_34873338/article/details/79483453