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. 字符编码乱码问题(servlet底层 编码大揭秘)

    好多初学者会遇到,请求过去的信息内包含中文(一般会是get方式提交过去的请求会出现).好郁闷,这是为什么呢.有下面分析下,说的不好可以吐槽 话说我们能遇到这种编码的问题,归根结底就是这  这 web开 ...

  2. 页面渲染——简化paint复杂程度和区域

    Paint是填充像素并且最后合成在用户的屏幕上的过程. 通常是在管道中耗费最大的,你要尽可能的避免使用paint. 动画中使用除了transform和opacity的动画属性都将触发paint pai ...

  3. Constructing Roads In JGShining's Kingdom

    点击打开题目链接 本题目是考察  最长递增子序列的  有n^2     n(logn)  n^2  会超时的 下面两个方法的代码  思路  可以百度LIS  LCS dp里面存子序列 n(logn) ...

  4. CodeForces526F:Pudding Monsters (分治)

    In this problem you will meet the simplified model of game Pudding Monsters. An important process in ...

  5. SPOJ(后缀数组求不同子串个数)

    DISUBSTR - Distinct Substrings Given a string, we need to find the total number of its distinct subs ...

  6. kafka之五:如何手动更新Kafka中某个Topic的偏移量

    本文介绍如何手动跟新zookeeper中的偏移量.我们在使用kafka的过程中,有时候需要通过修改偏移量来进行重新消费.我们都知道offsets是记录在zookeeper中的,所以我们想修改offse ...

  7. 生产环境下Flask项目目录构建

    接触Flask已经有大半年了,本篇博客主要来探讨如何规范化生产环境下Flask的项目目录结构.虽然目录结构见仁见智,个人有个人的看法和习惯,但总的来说,经过很多人的实践和总结,还是有很多共同的意见和想 ...

  8. 3-2if条件结构

    不同条件做不同的操作.例如满100就减去20 条件结构 package com.imooc.operator; public class ConditionDemo1 { public static ...

  9. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">详解

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. E20180608-hm

    更新: 2019/02/19 原来忘记分类,把此博文归入单词类 capacity  n. 容量; 性能; 才能; 生产能力;