shiro添加注解@RequiresPermissions無效


在學習和使用shiro中,需要整合shiro框架,然后可以在spring中中使用有三種方法,我用的是注解開發這種方式,但是,我加入注解后發現,沒什么作用,然后想着肯定是沒有注解成功,然后查找資料,發現是沒有開啟spring攔截器,那么怎么開啟呢,如下所示

在spring-mvc.xml中加入以下代碼就可以了(一定要寫在最先加載的xml中,寫在后面加載的xml中也不起作用)

 

    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
          depends-on="lifecycleBeanPostProcessor" />
    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
        <property name="securityManager" ref="securityManager" />
    </bean>

lifecycleBeanPostProcessor和securityManager是在shiro配置文件中定義好的

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

    <!-- 配額securityManager -->
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="realm" ref="customRealm" />
        <!-- 注入緩存管理器 -->
        <property name="cacheManager" ref="cacheManager"/>
    </bean>

一會總結一下springmvc+shiro的整合配置


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM