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 ...
随机推荐
- 201621123002《JAVA程序设计》第四周学习总结
1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 继承 多态 覆盖 抽象 重载 1.2 尝试使用思维导图将这些关键词组织起来.注:思维导图一般不需要出现过多的字. 1.3 可选: ...
- ad_imh
1. stc15 ad_1.7 9600 1t #include < #include <absacc.h> #include <stdio.h> #includ ...
- MySQL—查询某时间范围的数据
-- 查询今天的数据 select * from `user` where to_days(birthday) = to_days(CURDATE()); -- 查询昨天的数据 select * fr ...
- C#当中的扩展方法
先说有用的,c#扩展方法结论: 扩展方法能够向现有类型“添加”方法,而无需创建新的派生类型,重新编译或以其他方式修改原始类型.扩展方法必须是静态方法,可以像实例方法一样进行调用.且调用同名中实际定义的 ...
- virtual和abstract的区别
virtual和abstract都是用来修饰父类的,前面不能用private私有,要不然就会出现编译错误:虚拟方法或抽象方法是不能私有的. 毕竟加上virtual或abstract就是让子类重新定义 ...
- Noxim Overview
PE+Router= Tile Node Architectural Elements: Buffer.h, Router.h, LocalRoutingTable.h, Tile.h, NoC.h, ...
- 学以致用二十七-----Centos7.5二进制安装mysql5.7.23
首先去官网查看mysql版本.才一个礼拜不到,我之前下载的是mysql5.7.23,现在在官网页面已然找不到了,只有5.7.24版本,不得不说更新真快.不过我下载的是mysql5.7.23,所以还是安 ...
- oracle数据库创建分区表
参考资料:http://blog.chinaunix.net/uid-21943216-id-4062400.html 一.建按月自增分区表:1.1建表SQL> create table mon ...
- hive 语法 case when 语法
' then '精选' else null end as sale_type 注意: end不能少
- 隐藏字符 BOM
如果您在修改任何PHP文件後发生: * 不能登入或者不能登出: * 页顶出现一条空白: * 页顶出现错误警告: * 其它不正常的情况. 则多半是编辑器的问题. 本程序采用UTF-8编码.现在几乎所 ...