SpringBoot整合SpringSecurity,报错Can‘t configure anyRequest after itself

忽略springsecurity默认登录验证时报错:java.lang.IllegalStateException: Can‘t configure anyRequest after itself 项目场景: 搭建Springboot+SpringSecurity+JWT的登录项目 问题描述: 搭建好项目后需要启动测试,但引入了springsecurity的项目每次测试的时候需要输入默认账号跟密码!!!!!非常的麻烦,这里就需要忽略每次进入页面时默认的登录验证操作,springboot1.5之前忽略springsecurity通过配置文件的方式,此处贴出springboot2.x的配置方式,通过新建配置类的方式实现忽略验证!!!! @Configuration @EnableWebSecurity 阅读详情

问题

SpringBoot整合SpringSecurity,项目一启动就失败,报错显示

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: Can't configure anyRequest after itself
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:483) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:311) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at com.chen.demo.DemoApplication.main(DemoApplication.java:10) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: Can't configure anyRequest after itself
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	... 22 common frames omitted
Caused by: java.lang.IllegalStateException: Can't configure anyRequest after itself
	at org.springframework.util.Assert.state(Assert.java:76) ~[spring-core-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry.anyRequest(AbstractRequestMatcherRegistry.java:74) ~[spring-security-config-5.3.3.RELEASE.jar:5.3.3.RELEASE]
	at com.chen.demo.ActuatorSecurity.configure(ActuatorSecurity.java:17) ~[classes/:na]
	at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.getHttp(WebSecurityConfigurerAdapter.java:231) ~[spring-security-config-5.3.3.RELEASE.jar:5.3.3.RELEASE]
	at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:322) ~[spring-security-config-5.3.3.RELEASE.jar:5.3.3.RELEASE]
	at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:94) ~[spring-security-config-5.3.3.RELEASE.jar:5.3.3.RELEASE]
	at com.chen.demo.ActuatorSecurity$$EnhancerBySpringCGLIB$$5abc84c3.init(<generated>) ~[classes/:na]
	at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.init(AbstractConfiguredSecurityBuilder.java:370) ~[spring-security-config-5.3.3.RELEASE.jar:5.3.3.RELEASE]
	at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:324) ~[spring-security-config-5.3.3.RELEASE.jar:5.3.3.RELEASE]
	at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:41) ~[spring-security-config-5.3.3.RELEASE.jar:5.3.3.RELEASE]
	at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:104) ~[spring-security-config-5.3.3.RELEASE.jar:5.3.3.RELEASE]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	... 23 common frames omitted

解决

还是配置的时候大意了,Security的配置类的configure(HttpSecurity http)方法中,
没有删掉super.configure(http);
只要删掉super.configure(http)即可。

# springboot springcloud微服务搭建测试填坑实录 springboot springcloud微服务搭建测试 1)step 1 https://blog.csdn.net/csuzxm2000/article/details/86511847 2) step 2 创建Eureka注册中心https://blog.csdn.net/csuzxm2000/article/details/86509088 注意:由于我采用的版本是springboot ... 阅读详情

相关推荐

一篇文章带你解决 SpringSecurity 出现: “Error creating bean with name ‘springSecurityFilterChain‘”

我出现这个问题的 SpringBoot 版本是 2.3.4,java 版本是 11 文章目录一、问题描述二、问题解决 一、问题描述 对于springsecurity 的其他配置没出现什么问题,将其和 Oauth2 结合使用时,出现: 错误信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘springSecurityFilterChain’ defined in class

南淮北安的博客 9253

Spring Security错误

因为一个“/”引发的异常灾难 因为少写了一个“/”符号,浪费我大量时间,搞笑,定向的是 方法 而不是界面 Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled. 2018-09-18 16:32:29.662 ERROR 763...

Marryme丿任 4016

UWB定位原理详细介绍

Hello大家好我是小智,今天我来给大家介绍下超宽带的定位原理,首先我们来讲下什么是UWB技术。 超宽带(Ultra Wide Band)简称UWB,和我们熟悉的WIFI、蓝牙技术一样属于通信技术的一种,UWB是一种无线载波通信技术,它不采用正弦载波,而是利用纳秒级的非正弦波窄脉冲传输数据,其所占的频谱范围很宽,右图是一种典型的正弦载波信号图。 UWB这种技术有什么特点呢? UWB系统结构实现简单;2.具有高速的数据传输能力;3.功耗低;4.安全性高;5.多径分辨能力强;6.可用于精确定位等特点。 UWB.

qq_35699674的博客 2万+

Factory method 'springSecurityFilterChain' threw exception

报错信息 Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2019-08-13 12:11:33.449 ERROR 32796 --- [ main] o.s.boot.Spring...

tripleDemo的博客 1万+

从SolidWorks到Simscape:URDF导出模型错位的5个常见原因及修复方法

本文深入分析了从SolidWorks导出URDF模型到Simscape时出现模型错位的5个常见原因,包括坐标系定义、RPY角陷阱、轴方向统一、质量属性导出和层次结构错乱,并提供了详细的修复方法和实战技巧,帮助工程师高效解决模型错位问题。

weixin_30664051的博客 444

ANSYS MAXWELL内置式永磁同步电机(IPMSM)转矩最大时输入电流相位的确定

1.在转子转速为零时看一个周期内的转矩变化

qq_41752507的博客 6523

异常记录-3

org.springframework.beans.BeanInstantiationException

weekeight 1705

PostgreSQL和PostGIS安装、导入shp或gdb格式数据至数据库、使用QGIS测试上传PstGIS数据库操作和代码

本文详细介绍了postgresql和postgis安装步骤,并且使用postgis测试上传shp和gdb格式的矢量数据至数据库,包括步骤和代码,并使用qgis连接postgis数据查看数据库里的数据,数据依旧和本地数据一样可查看可编辑,方便后续数据底座开发和服务。

weixin_46456488的博客 1252

Springboot项目启动遇到问题

我尝试排查过代码块的问题,但是具体是没问题的,依赖配置后依然没有用。"BeanInstantiationException" 表示Spring无法创建 "javax.servlet.Filter" 类型的实例,并且错误的原因是 "springSecurityFilterChain" 工厂方法。太离谱了,竟然缺少这个依赖,按理说导入springboot-starter的依赖这个依赖是会自动导入的,为啥需要手动导入,否则就会启动出错呢,这个问题至今仍然没有思考清楚,但是加入这个依赖确实项目就跑起来了。

weixin_52309620的博客 1745

PAM4信号测试实战:从眼图分析到误码率测量的技术演进

在高速数字系统设计中,信号完整性测试是确保数据传输可靠性的核心环节。其基本原理在于通过时域和频域分析,精确评估信号在传输过程中的质量衰减与失真。随着数据速率向56Gbps及以上演进,传统的NRZ编码面临带宽瓶颈,而PAM4调制技术通过在每个符号周期内承载更多比特信息,成为提升信道效率的关键路径。这项技术的工程价值在于,它允许在相同带宽下实现翻倍的数据吞吐量,这对于数据中心互联、PCIe 6.0及800G以太网等高速接口至关重要。然而,PAM4信号电平间距更小,对噪声和抖动极为敏感,导致其原始误码率显著升高,

weixin_42522817的博客 678

RTK_ROS_导航(1): GNSS里程计

1. RTK 配置 4G CORS + 4G 网络 + 户外有信号,不能实现RTK,就恢复出厂设置 输出信息包含(一般需要三个同时打开): GAPPA:包含位置信息 GPVTG:包含速度信息 GPHDT:包含定向的朝向信息 2. ROS驱动 驱动安装sudo apt install ros-noetic-nmea-navsat-driver 运行,需要修改该功能包的启动端口,会自动解析上面的3个RTK语句信息roslaunch nmea_navsat_driver nmea_serial_d

旋风小短腿 4270

SpringSecurity异常:Can‘t configure anyRequest after itself

如同异常字面意思,在SpringSecurity的安全拦截请求配置中,如果已经使用了anyRequest,则不能使用第二次。

qq_50735685的博客 1106

手把手教你RK3568 MIPI屏驱动适配,纯干货!

RK3568 作为一款高性能的多媒体处理器,在嵌入式领域中备受瞩目。它采用了先进的 22nm 制程工艺,搭载四核 Cortex-A55 处理器,这种架构为芯片提供了高效的功耗比,使其在运行各种复杂任务时,既能保证性能,又能有效控制功耗。在实际应用中,无论是多任务处理还是运行大型应用程序,RK3568 都能凭借其四核 Cortex-A55 处理器,实现流畅的操作体验,满足智能设备对高性能和低功耗的需求。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 4081

springboot项目中运行spring security 报 Error creating bean with name 'springSecurityFilterChain'。。。。错误

springboot版本:1.5.9 spring security版本:1.5.9 问题描述: 启动springboot项目,直接编译报错,内容: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' define...

qq_37736010的博客 3万+

ROS2 - 乐动激光雷达 LD06

STL-06P 主要由激光测距核心,无线传电单元,无线通讯单元,角度测量单元、电机驱动单元和机械外壳组成。STL-06P 测距核心采用 DTOF 技术,可进行每秒 5000 次的测距。每次测距时,雷达发射出红外激光,激光遇到目标物体后被反射到单光子接收单元。

机器人控制与仿真应用 3504

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

异常记录-4

org.springframework.beans.BeanInstantiationException

weekeight 889

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

【Java】遇到Factory method ‘highLevelClient‘ threw exception问题

之前在做SpringBoot整合Elasticsearch客户端的时候遇到下面的问题 Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'highLevelClient' defined in class path r

Kida 的躺平小屋 3258

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Error c nested exception is java.lang.IllegalStateException: Can‘t configure anyRequest after itself

Can’t configure anyRequest after itself: 无法在自身之后配置 anyRequest主要问题是调用了两次这个方法 把上面的移到最后面就可以了

dshakjhfvf的博客 2865

整合elasticsearch-rest-high-level-client报错nested exception is java.lang.NoSuchFieldError:IGNORE_DEPREC

报错信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restHighLevelClient' defined in class path resource [com/whf/search/config/ElasticSearchConfig.class]: Bean instantiation via factory method failed; nested exce

weixin_41645232的博客 5791

springboot-security报错-Can‘t configure anyRequest after itself

springboot2.4.1 与security @Override protected void configure(HttpSecurity http) throws Exception { //通过配置实现,不需要JWT令牌就可以访问的接口 for(String uri : jwtProperties.getPermitAllURI()){ http .authorizeRequests().a

草叶儿的博客 3516

springboot3+springsecurity6集成druid启动报错

This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher)

给自己的程序生涯留下一点痕迹 2710

org.springframework.beans.factory.BeanCreationException

具体的错误原因是工厂方法’springSecurityFilterChain’抛出了异常,而该异常是由java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException引起的。但是,从Java 11开始,JAXB已经被标记为过时(Deprecated)并移出标准Java库,取而代之的是Jakarta XML绑定(Jakarta XML Binding,或简称为Jakarta JAXB,属于Jakarta EE项目的一部分)。

Artij的博客 2013

记一次SpringSecurity5.2版本出现Can’t configure anyRequest after itself问题

记一次SpringSecurity5.2版本出现Can’t configure anyRequest after itself问题 问题: 笔者最近使用SpringSecurity做权限功能时候,出现了Can’t configure anyRequest after itself 的问题,上网查了很久千篇一律都是说调用了 父类种的configure方法:super.configure(http) 但检查下来之后并不是这个问题,后面找到了一个看似正确的答案,说是SpringSecurity自从5.2版本更新之

qq_28455595的博客 1231

poi jar包报错:java.lang.NoSuchFieldError:Factory

解决jar包报错:java.lang.NoSuchFieldError: Factory

day day up 3万+

Spring报错解决一览

Spring错误持续更新贴...... 问题一 springcloud-OAuth2.0配置的时候报错 Method springSecurityFilterChain in org.springframework.security.config.annotation.web.configuration.WebSecurityConfig...

7402
上一篇: SpringBoot读取ValidationMessages.properties,中文乱码
下一篇: SpringBoot整合AdminServer,项目启动失败
小彩虹冲鸭
博客等级 码龄12年 92粉丝 114原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值