shiro添加註解@RequiresPermissions不起作用

方法一:

在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>

<!-- Shiro安全管理器 -->
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="realm" ref="jdbcRealm"></property>
        <property name="cacheManager" ref="cacheManager"></property>
    </bean>
複製代碼

 

方法二:

由於fillter是在spring容器中,而不是在springmvc容器中,所以不起作用。那麼把@RequiresPermissions註解挪到service中就可以了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章