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

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

根据错误信息可以看出是服务器启动springSecurityFilterChain没有找到"springSecurityFilterChain"bean。

因为spring security是使用java配置的,因此我在spring mvc的xml配置文件中添加了对spring security配置类的扫描,但是运行时却报错没有发现该bean

因此通过网络查阅资料后发现,因为我们在web.xml中注册spring mvc 的dispatcherServlet时,是使用<init-param>加载的配置文件,而通过<init-param>初始化的对象

只能在servlet中使用,但是我们这里的springSercurityFilterChain bean是需要在springSercurity的Filter中使用,因此我们需要在<context-param>中初始化,<context-param>中初始化的对象全局有效

因此将springSercurity的配置类放在applicationContext.xml配置文件中注册

具体操作如下:

在web.xml添加如下

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

在applicationContext.xml文件中添加

<bean class="config.SecurityConfig"></bean>

使用java配置spring security时,可以通过实现AbstractSecurityWebApplicationInitializer类来创建该Filter,只需要实现就行

public class SecurityInitializer extends AbstractSecurityWebApplicationInitializer {
}

实现该抽象类的效果相当于在web.xml中配置springSecurityFilterChain

<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>

Spring Security使用报错 No bean named 'springSecurityFilterChain' is defined的更多相关文章

  1. No bean named 'springSecurityFilterChain' is defined

    1.问题 本文讨论Spring安全配置问题 - 应用程序引导过程抛出以下异常: SEVERE: Exception starting filter springSecurityFilterChain ...

  2. Spring学习过程中遇到的No bean named 'beanId' is defined报错

    ApplicationContext applicationContext= new ClassPathXmlApplicationContext("bean.xml");Obje ...

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

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

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

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

  5. Springboot2.x 启动报错:Bean named 'xxxService'... but was actually of type 'com.sun.proxy.$Proxy82'

    Springboot 2.0.5 搭建一个新项目启动后报错:Bean named 'xxxService'... but was actually of type 'com.sun.proxy.$Pr ...

  6. 报错!!!!!!!!!!!org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSessionRepositoryFilter' is defined

    报错!!!!!!!!!!! 因用maven项目不是很熟练,经常在Maven转Web项目(为什么要转web项目?因为要在tomcat中跑起来.maven项目好像是可以直接部署到tomcat的,或集成to ...

  7. .net core中Grpc使用报错:The remote certificate is invalid according to the validation procedure.

    因为Grpc采用HTTP/2作为通信协议,默认采用LTS/SSL加密方式传输,比如使用.net core启动一个服务端(被调用方)时: public static IHostBuilder Creat ...

  8. adb驱动安装和使用报错笔记

    adb驱动安装 adb驱动下载地址:https://adb.clockworkmod.com/ 安装时候选择一个容易记住的路径,这个很重要,因为adb驱动没有自动配置环境变量,所以实验时候将adb安装 ...

  9. animate is not a function(zepto 使用报错)[转]

    animate is not a function(zepto 使用报错) 1.为什么使用zepto写animate报错? 因为zepto默认构建包含: Core, Ajax, Event, Form ...

随机推荐

  1. Quartz.NET快速入门指南

    最近,在工作中遇到了 Quartz.net 这个组件,为了更好的理解项目代码的来龙去脉,于是决定好好的研究一下这个东西.确实是好东西,既然是好东西,我就拿出来分享一下.万丈高楼平地起,我们也从入门开始 ...

  2. eclipse-查看继承层次图/继承实现层次图

    阅读代码时,如果想要看某个类继承了哪些类.实现了哪些接口.哪些类继承了这个类,恰巧这个类的继承实现结构又比较复杂,那么如果对开发工具不是很熟练,这个需求是比较难以实现的.eclipse中的type h ...

  3. 用nodejs搭建类似于C++的服务器后台.类似网易pomelo

    实际的情况,用nodejs跑业务,非常的快,只要用好其无阻塞和回调这两点,处理速度真的是杠杠的. 从年初开始,我用nodejs搭建了类似C++的服务器后台,也想和做同样的事情的朋友分享,本服务平台因为 ...

  4. 游戏脚本编程 文本token解析

    一个数字的组成由以下几个字符 正负号 + -   小数点 .   数字 0-9 比如 3 -3 3.13 -34.2234 但是符号和小数点不会出现多次 那么识别流程用图来表示 则是 整数 浮点数 一 ...

  5. Python 多进程编程之multiprocessing--Process

    Python 多进程编程之multiprocessing 1,Process 跨平台的进程创建模块(multiprocessing), 支持跨平台:windowx/linux 创建和启动      创 ...

  6. 339. Nested List Weight Sum

    https://leetcode.com/problems/nested-list-weight-sum/description/ Given a nested list of integers, r ...

  7. 滑块视图容器   swiper

    属性名 类型 默认值 说明 indicator-dots Boolean false 是否显示面板指示点 autoplay Boolean false 是否自动切换 current Number 0 ...

  8. C语言中的语句

    • 表达式语句 表达式后加 ; 构成表达式语句. a = b+c; x+y i++ • 控制语句 完成一定的控制功能. if(...){...}else{...}                   ...

  9. 20155326《网络攻防》Exp4 恶意代码分析

    20155326<网络攻防>Exp4 恶意代码分析 基础问题回答: 1)如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操作有哪 ...

  10. Codeforces828 B. Black Square

    B. Black Square time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...