今天配置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. BeanUtils.copyProperties的简单示例

    一.新建测试实体 1.UserA package com.dechy.hebswj.test; public class UserA { private String a; private Strin ...

  2. 微信小程序设置背景铺满全屏

    参考方法: 新版本升级取消了默认page的100%的特性 需要在app.wxss文件中加入如下代码: page{ height:100%; }

  3. fine安装教程

    先关掉lmgrd 相关的两个进程 -关闭当前license server 1. Login root 2. 执行 FineTurbo11.1_linux 文件夹内 ./install_numeca 3 ...

  4. python 03 字符串详解

    1.制表符 \t str.expandtabs(20) 可相当于表格 2.def   isalpha(self) 判断是否值包含字母(汉字也为真),不包含数字 3.def   isdecimal(se ...

  5. Python之路(第二十八篇) 面向对象进阶:类的装饰器、元类

    一.类的装饰器 类作为一个对象,也可以被装饰. 例子 def wrap(obj): print("装饰器-----") obj.x = 1 obj.y = 3 obj.z = 5 ...

  6. SpringBoot集成redis,使用@Cachexxxx

    一.引入相关依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId& ...

  7. centos7安装python3.6后导致防火墙功能无法正常工作的解决办法

    问题:因为默认python版本被设置成了python3.6,而进行防火墙的指令操作频频报错. Jul 19 16:30:51 localhost.localdomain systemd[1]: Sta ...

  8. winSocket编程(十)完成端口

    //本篇为转贴 本系列里完成端口的代码在两年前就已经写好了,但是由于许久没有写东西了,不知该如何提笔,所以这篇文档总是在酝酿之中……酝酿了两年之后,终于决定开始动笔了,但愿还不算晚….. 这篇文档我非 ...

  9. Linux使用MentoHust联网线上校园网, 回到普通有线网络却连不上?

    我的解决方法如下: 在有线网的设置(Wired Settings)那里, 弹出Network窗口, 点击右下角的设置图标, 选择Security, 然后关掉802.1x Security. 然后就可以 ...

  10. 浅析软件工程中的UML建模技术

    一.基本信息 标题:浅析软件工程中的UML建模技术 时间:2018 出版源:电子世界 领域分类:软件工程:UML建模技术:需求分析 二.研究背景 问题定义:软件工程中UML建模技术的研究 难点:明确软 ...