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. Objective-C学习之解析XML

    通过soap请求webservice时,返回的数据是XML类型,有时候也需要解析本地的xml数据等,苹果自带类NSXMLParser解析xml还是很方便的,简单轻便 本文以解析本地XML为例,网络获取 ...

  2. Android-低功耗蓝牙(BLE)-客户端(主机/中心设备)和服务端(从机/外围设备)

    一.Android 低功耗蓝牙(BLE)的API简介 从Android 4.3(API 18)才支持低功耗蓝牙(Bluetooth Low Energy, BLE)的核心功能, BLE蓝牙协议是GAT ...

  3. 细谈HTML解析模块

     细谈HTML解析模块 Html在网页中所占的位置,用一个简单直观的图给展示一下:    

  4. chan_ss7 呼出的时候指定使用某个CICs,或者CICs范围 的方法

      Linkset one: 1-31 Incoming 33-58 Outgoing 58-63 Emergency Traffic Linkset two: 1-31 Incoming 33-58 ...

  5. Subset Sums

    链接 分析:dp[i][j]表示前i个数能够组成j的对数,可得dp[i][j]=dp[i-1][j]+dp[i-1][j-i],所以最后dp[n][sum/2]既是所求 /* PROB:subset ...

  6. LuoguP4861 按钮

    传送门 这题一眼看上去要解\(k^x \equiv 1(mod\ m)\)的最小正整数解. 于是我打了一个扩展BSGS 这题这样做算的答案一直是0的.不过有另一个定理欧拉定理,\(k^{\varphi ...

  7. C++之友元机制(友元函数和友元类)

    一.为什么引入友元机制? 总的来说就是为了让非成员函数即普通函数或其他类可以访问类的私有成员,这确实破坏了类的封装性和数据的隐蔽性,但为什么要这么做呢? (c++ primer:尽管友元被授予从外部访 ...

  8. 《Objective-C高级编程》の内存管理の学习笔记

    此日志用于记录下学习过程中碰到的问题 转载请注明出处: http://www.cnblogs.com/xdxer/p/4069650.html <Objective-C高级编程> 人民邮电 ...

  9. phpstudy打不开localhost(Apache)

    1.先打开httpd.conf文件,打开httpd-vhosts.conf "Include conf/extra/httpd-vhosts.conf"的注释,启动服务时优先加载此 ...

  10. 在xshell中使用Linux语言打开错误提示

    上线项目到服务器后, 有时候有的功能跟本地调试的不一样,这时候就需要设置打开display_errors = On: 首先,cd .. 进入上一级,ll 罗列当前目录,跟home当前目录的有这个usr ...