1.问题

本文讨论Spring安全配置问题 - 应用程序引导过程抛出以下异常:

SEVERE: Exception starting filter springSecurityFilterChain
org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'springSecurityFilterChain' is defined

2.原因

此异常的原因很简单 - Spring Security查找名为springSecurityFilterChain的bean(默认情况下),但无法找到它。主要的Spring安全过滤器 - DelegatingFilterProxy - 在web.xml中定义了这个bean:

<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

这只是一个代理,它将其所有逻辑委托给springSecurityFilterChain bean

3.解决方案

上下文中缺少此bean的最常见原因是security XML配置没有定义元素:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> </beans:beans>

如果使用XML配置Security命名空间 - 如上例所示,则声明一个简单的元素将确保创建过滤器bean并且所有内容都正确启动:

<http auto-config='true'>
<intercept-url pattern="/**" access="ROLE_USER" />
</http>

另一个可能的原因是Security配置根本不会导入到Web应用程序的整体上下文中。

如果安全性XML配置文件名为springSecurityConfig.xml,请确保导入资源:

@ImportResource({"classpath:springSecurityConfig.xml"})

或者用XML:

<import resource="classpath:springSecurityConfig.xml" />

最后,可以在web.xml中更改过滤器bean的默认名称 - 通常使用带有Spring Security的现有过滤器:

<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>customFilter</param-value>
</init-param>
</filter>

4.总结

文讨论了一个非常具体的Spring Security问题 - 缺少过滤器链bean - 并展示了这个常见问题的解决方案

No bean named 'springSecurityFilterChain' is defined的更多相关文章

  1. Spring Security使用报错 No bean named 'springSecurityFilterChain' is defined

    今天配置spring security时,运行报出No bean named 'springSecurityFilterChain' is defined错误,报错信息如下 严重: Exception ...

  2. Spring:No bean named 'beanScope' is defined

    初学Spring,“No bean named 'beanScope' is defined”这个问题困扰了我好几个小时,查资料无果后,重写好几遍代码后发现问题居然是配置文件不能放在包里...要放在s ...

  3. No bean named 'transactionManager' is defined

    2016-10-20 23:27:17.771 INFO 7096 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped &quo ...

  4. org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSessionRepositoryFilter' is defined

    spring-session 集成redis,web.xml配置filter时候出现  No bean named 'springSessionRepositoryFilter' is defined ...

  5. No bean named 'hibernateTemplate' is defined

    1.错误描述 WARN:2015-05-01 15:42:22[localhost-startStop-1] - Exception encountered during context initia ...

  6. No bean named 'sessionFactory' is defined

    1.错误描述 严重:Servlet service() for servlet default threw exception . org.springframework.beans.factory. ...

  7. No bean named 'cxf' is defined

    1.错误描述  严重:Exception starting filter CXFServlet        org.springframework.beans.factory.NoSuchBeanD ...

  8. No bean named 'xxxxx' is defined异常,已解决,这个坑很难发现,你get了吗

    出现No bean named 'xxxxx' is defined异常 没有定义名为xxx的bean 如果你的代码写的都对,根本问题只有一个地方出错了,那就是你的 basePackage=的包名路径 ...

  9. spring集成shiro报错解决(no bean named 'shiroFilter' is defined)

    引言: 本人在使用spring集成shiro是总是报“no bean named 'shiroFilter' is defined”,网上的所有方式挨个试了一遍,又检查了一遍, 还是没有解决,最后,抱 ...

随机推荐

  1. Ueditor文本编辑工具栏自定义

    1.找到 ueditor.config.js 文件 2.在 toolbars 数组内进行删减,添加 , toolbars: [[ 'fullscreen', 'source', '|', 'undo' ...

  2. 「LuoguP1430」 序列取数(区间dp

    题目描述 给定一个长为n的整数序列(n<=1000),由A和B轮流取数(A先取).每个人可从序列的左端或右端取若干个数(至少一个),但不能两端都取.所有数都被取走后,两人分别统计所取数的和作为各 ...

  3. vue不支持IE8的原因

    当你把一个普通的 JavaScript 对象传给 Vue 实例的 data 选项,Vue 将遍历此对象所有的属性, 并使用 Object.defineProperty 把这些属性全部转为 getter ...

  4. html锚点实现的方法

    1 通过id <a href="#div1"> 通过id获取锚点</a> <div style=" height:200px; width: ...

  5. bzoj4006

    斯坦纳树 比之前要求高了一些 其实利用斯坦纳树的dp[i][s]以i为根,S为状态就行了,先跑一遍斯坦纳树,预处理出dp数组,记住每个S的最小值,然后再dp,这里dp必须要求同一种颜色的状态都必须在S ...

  6. CF-798C

    C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  7. ASP.NET页面执行顺序

    原文地址:http://blog.csdn.net/a497785609/article/details/4510335 1.对象初始化(OnInit方法) 页面中的控件(包括页面本身)都是在它们最初 ...

  8. GcSpreadSheet自定义Tab键选择

    最开始的时候需要在GcSpreadSheet中按Tab在需要输入的cell中切换,在模板中定义Tab的切换规则:后来又有一个新的要求,因为在使用的时候会出现数据不平的情况,这个时候需要在标记中的不平数 ...

  9. 使用js在html文档的任意位置输出内容

    <script type="text/javascript">document.write('这里是内容');</script>

  10. 5-2 Windows消息队列 (25分)

    5-2 Windows消息队列   (25分) 消息队列是Windows系统的基础.对于每个进程,系统维护一个消息队列.如果在进程中有特定事件发生,如点击鼠标.文字改变等,系统将把这个消息加到队列当中 ...