在学习和使用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的整合配置

相关文章:

  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-21
  • 2021-09-17
  • 2021-08-19
  • 2021-09-05
相关资源
相似解决方案