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. POJ3061 Subsequence

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16520   Accepted: 7008 Desc ...

  2. 用libtommath实现RSA算法

    RSA算法描述: 1) 选择两个大素数 p.q, 计算 n = p*q; 2) 产生 e, d 使: e*d = 1mod(p-1)(q-1) e 与 (p-1)(q-1) 互质 [公钥] e.n [ ...

  3. JavaScript-Tool:jquery.md5.js

    ylbtech-JavaScript-Tool:jquery.md5.js 1.返回顶部 1. 引入js后 使用方法:document.write($.md5('1234')); 加密结果:81dc9 ...

  4. 三、mysql登录详解及版本号查询

    1.用window+r,输入cmd,用mysql -uuser -ppassword登录时出现‘mysql’不是有效的内部命令? 答:这是因为没有配置MySQL的环境变量path所致. MySQL的环 ...

  5. Yet Another Number Sequence

    题意: $F_0 = 0, F_1 = 1, F_n = F_{n-1} + F_{n-2}$ 求解$\sum_{i=1}^n{ F_i i^K } \  mod \  10^9+7$. 解法: 记$ ...

  6. 我所理解的Restful API最佳实践

    一直在公司负责API数据接口的开发,期间也遇到了不小的坑,本篇博客算是做一个小小的记录. 1. 不要纠结于无意义的规范    在开始本文之前,我想先说这么一句:RESTful 真的很好,但它只是一种软 ...

  7. mysql分页性能

    - select * from userinfo limit 20000,10  # 数据越往后越慢 - 索引表中扫: select * from userinfo where id in (sele ...

  8. c++重载输入输出运算符

    1 最好打断点看看哦 2例子 #include <iostream> using namespace std; class Complex2 { public: Complex2(, ) ...

  9. CodeForces660B【模拟—水】

    感觉模拟题用函数分块写比较清晰~传参的话,字符串要么直接全局,或者指针也是容易操作,总之思路清晰,然后分块清晰,模拟wa的少吧. 这题水题,不说了. #include <bits/stdc++. ...

  10. DirectX实现球面纹理映射

    http://www.cnblogs.com/graphics/archive/2011/09/13/2174022.html DirectX实现球面纹理映射 介绍 球面纹理映射就是将一个平面纹理映射 ...