Spring Security使用报错 No bean named 'springSecurityFilterChain' is defined
今天配置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的更多相关文章
- No bean named 'springSecurityFilterChain' is defined
1.问题 本文讨论Spring安全配置问题 - 应用程序引导过程抛出以下异常: SEVERE: Exception starting filter springSecurityFilterChain ...
- Spring学习过程中遇到的No bean named 'beanId' is defined报错
ApplicationContext applicationContext= new ClassPathXmlApplicationContext("bean.xml");Obje ...
- spring集成shiro报错解决(no bean named 'shiroFilter' is defined)
引言: 本人在使用spring集成shiro是总是报“no bean named 'shiroFilter' is defined”,网上的所有方式挨个试了一遍,又检查了一遍, 还是没有解决,最后,抱 ...
- Spring:No bean named 'beanScope' is defined
初学Spring,“No bean named 'beanScope' is defined”这个问题困扰了我好几个小时,查资料无果后,重写好几遍代码后发现问题居然是配置文件不能放在包里...要放在s ...
- 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 ...
- 报错!!!!!!!!!!!org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSessionRepositoryFilter' is defined
报错!!!!!!!!!!! 因用maven项目不是很熟练,经常在Maven转Web项目(为什么要转web项目?因为要在tomcat中跑起来.maven项目好像是可以直接部署到tomcat的,或集成to ...
- .net core中Grpc使用报错:The remote certificate is invalid according to the validation procedure.
因为Grpc采用HTTP/2作为通信协议,默认采用LTS/SSL加密方式传输,比如使用.net core启动一个服务端(被调用方)时: public static IHostBuilder Creat ...
- adb驱动安装和使用报错笔记
adb驱动安装 adb驱动下载地址:https://adb.clockworkmod.com/ 安装时候选择一个容易记住的路径,这个很重要,因为adb驱动没有自动配置环境变量,所以实验时候将adb安装 ...
- animate is not a function(zepto 使用报错)[转]
animate is not a function(zepto 使用报错) 1.为什么使用zepto写animate报错? 因为zepto默认构建包含: Core, Ajax, Event, Form ...
随机推荐
- Agile PLM 表结构说明
1. Activity:项目表class表示大类(关口和活动),subclass表示小类(关口,任务,计划,阶段)subclass=18027:计划(项目),subclass=18028:阶段, ...
- thinkphp 视图(一)
视图 View <?php namespace app\index\controller; class Index{ public function index(){ return view() ...
- json-server使用及路由配置
1.先安装node.js,node.js中包含了json-server模块 2.在angular-hello/src/app/data-base.json文件中,编辑json格式的服务数据, { &q ...
- 【NIFI】 Apache NiFI 安装及简单的使用
NiFI介绍 NiFi(NiagaraFiles)是为了实现系统间数据流的自动化而构建的.虽然术语“数据流”用于各种上下文,但我们在此处使用它来表示系统之间的自动和管理信息流 官网地址:http:// ...
- sass基础常用指南
一.变量 $global-color:red; .nav{ background:$global-color; } 二.sass命名时横杠和下划线不区分 $global-color:yellow; . ...
- ABP框架系列之十二:(Audit-Logging-审计日志)
Introduction Wikipedia: "An audit trail (also called audit log) is a security-relevant chronolo ...
- 什么是servlet?
一.servlet是什么? 是用java编写的应用在服务端的程序,具有独立于平台和协议的特性,主要功能在于交互式地浏览和修改数据,生成动态Web内容,例如页面等等.从实现上讲,Servlet可以响应任 ...
- PHP直接查看换取的图片
<!doctype html><head> <title></title> <meta http-equiv="Content-Type ...
- python 使用多进程实现并发编程/使用queue进行进程间数据交换
import time import os import multiprocessing from multiprocessing import Queue, pool ""&qu ...
- 使用广播-BroadcastReceiver最详细解析
女孩:BroadcastReceiver是什么呀? 男孩:Broadcast是广播的意思,在Android中应用程序之间的传输信息的机制,BroadcastReceiver是接收广播通知的组件,广播和 ...