今天配置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. SQL 不常用的一些命令sp_OACreate,xp_cmdshell,sp_makewebtask

    开启和关毕xp_cmdshell   EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cm ...

  2. windows 性能监视器

    转载地址:https://www.cnblogs.com/luo-mao/p/5872374.html

  3. ActiveMQ_2安装

    Linux安装 环境JDK7以上 gz文件拷贝到 /usr/local/目录下 解压 后缀为 .tar.gz的压缩包 进入解压后的文件夹 cd apache-activemq-x.xx.x/ cd b ...

  4. Codeforces 1114 简要题解

    文章目录 A题 B题 C题 D题 E题 F题 传送门 然而这场div2div2div2没有什么难度比较大的题 A题 传送门 题意简述:三个人分别至少选x,y,zx,y,zx,y,z件物品,有三种物品数 ...

  5. (21)The history of human emotions

    https://www.ted.com/talks/tiffany_watt_smith_the_history_of_human_emotions/transcript00:12I would li ...

  6. Python_day5

    局部变量 全局变量 def test(): # 声明使用全局变量x global x x = 100 y = 300 # 局部变量:作用域和生存周期仅在从定义开始到函数结束 x = 200 # 全局变 ...

  7. C++ MFC棋牌类小游戏day4

    根据昨天的计划,今天开始做下面的内容. 1.鼠标点击事件 2.点击坐标进行处理.(坐标转换) 3.判断选中的位置是否有效. 4.确定选中的棋子,设置棋子的状态和棋子所在坐标的状态. 5.判断移动是否有 ...

  8. Linux命令之tee - 重定向输出到多个文件

    http://codingstandards.iteye.com/blog/833695 tee 将标准输出复制一份 ls -al | tee -a tmpls.log ls -al >> ...

  9. PLSQL基础知识-图片

    什么是PL/SQL?

  10. centos7系统下,配置学校客户端网络记录

    存在的情况 1.学校的网络客户端绑定了个人的电脑MAC地址.绑定了IP地址. 2.我有两台笔记本,一台用了4年多,想用这台(B)直接装centos7系统,然后新买的笔记本(A)做为经常用的,系统为wi ...