No bean named 'shiroFilter' is defined

问题:Spring在集成shiro,在启动时,报org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'shiroFilter' is defined

解决方法:

1)首先要确保applicationContext-shiro.xml文件中的ShiroFilterFactoryBean 的id属性要和webxml中DelegatingFilterProxy的名字要一样

1. applicationContext-shiro.xml配置文件

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">

<!--shiro 核心安全接口  -->

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

<!--登录时的连接  -->

<property name="loginUrl" value="/login.jsp"></property>

<!--登录成功之后要跳转的连接  -->

<property name="successUrl" value="/sysIndex.jsp"></property>

<!--未授权时跳转的连接  -->

<property name="unauthorizedUrl" value="/unauthorized.jsp"></property>

<!--filterChainDefinitions  -->

<property name="filterChainDefinitions">

<value>

/login/loginForm = anon

/logout = logout

/** = authc

</value>

</property>

</bean>

2. web.xml中的配置:

<filter>

<filter-name>shiroFilter</filter-name>

<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

</filter>

<filter-mapping>

<filter-name>shiroFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

2)web.xml中的上下文初始化参数中,要添加applicationContext-shiro.xml,确保Spring在初始化的时候,可以初始化到shiroFilter,这里需要注意的是冒号是英文状态下的

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>

classpath*:applicationContext.xml,

classpath*:applicationContext-shiro.xml

</param-value>

</context-param>

如果classptah后面的冒号写成中文了,就会导致初始化不了shiroFilter

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值