shiro框架搭建 org.springframework.beans.factory.NoSuchBeanDefinitionException

最近在初次学习shiro框架时,第一个Demo出现了如下错误:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'shiroFilter' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698)

at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175)...


<!-- 配置spring框架提供的用于整合shiro框架的过滤器  (一定要配置在struts2过滤器之前) -->
	<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>

仔细检查后,原来是没有在spring中配置shiro框架的过滤器工厂对象,添加如下配置文件:

<!-- 配置shiro框架的过滤器工厂对象 -->
	<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
		<!-- 注入安全管理器对象 -->
		<property name="securityManager" ref="securityManager"></property>

		<!-- 注入相关页面访问URL -->
		<property name="loginUrl" value="/login.jsp"></property>
		<property name="successUrl" value="/index.jsp"></property>
		<property name="unauthorizedUrl" value="/unauthorized.jsp"></property>

		<!-- 注入URL拦截规则 -->
		<property name="filterChainDefinitions">
            <value>
                /**=authc
            </value>
		</property>
	</bean>

	<!-- 注入安全管理器对象 -->
	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"></bean>
配置完毕,启动没有项目任何报错


猜你喜欢

转载自blog.csdn.net/weixin_41110459/article/details/81058331