当前位置: 首页 > news >正文

问题记录-Spring Security- bean httpSecurity not found

问题描述

最近使用Security的时候报了下面的错误:
在这里插入图片描述

配置如下:

@EnableWebSecurity
@Slf4j
public class SecurityConfig {@Resourceprivate CustUserService custUserService;@Beanpublic AuthenticationProvider authenticationProvider() {return new AuthenticationProvider() {@Overridepublic Authentication authenticate(Authentication authentication) throws AuthenticationException {String name = authentication.getName();String credentials = authentication.getCredentials().toString();UserDetails userDetails = custUserService.loadUserByUsername(name);if (credentials.equals(userDetails.getPassword())) {log.info("登录成功");return new UsernamePasswordAuthenticationToken(name, credentials, userDetails.getAuthorities());} else {log.info("登录失败");throw new BadCredentialsException("用户名密码错误");}}@Overridepublic boolean supports(Class<?> authentication) {return authentication.equals(UsernamePasswordAuthenticationToken.class);}};}@Beanpublic SecurityFilterChain filterChain(HttpSecurity http) throws Exception {http.authenticationProvider(authenticationProvider()).authorizeRequests((auth) -> {auth.anyRequest().authenticated();}).httpBasic(withDefaults());return http.build();}
}

我使用的是Springboot 2.3.3, 发现没有HttpSecurity注入Bean,SecurityFilterChain 是高版本的配置,所以不能在低版本使用。
解决方案一:可以参考这篇文章进行配置:
https://blog.csdn.net/bicheng4769/article/details/131205019

解决方案二:
升级Springboot 使用版本2.7.2,因为高版本给我们注入了这个Bean

在这里插入图片描述
此次踩坑告诉我,配置照网上粘贴如果遇到错误,可以检查一下是不是网上的版本和自己使用的版本有差异。

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • HarmonyOS Web组件(二)
  • 低代码与传统编程:快速高质量构建系统的比较与方法
  • 全新UI自助图文打印系统小程序源码/自助云打印机前后端源码
  • IDEA工具中Java语言写小工具遇到的问题
  • 在RK3568上如何烧录MAC?
  • Windows 11 version 22H2 中文版、英文版 (x64、ARM64) 下载 (updated Jul 2024)
  • flutter 充电气泡
  • 安卓系统签名的制作与使用(SignApk.jar)踩坑记录
  • 【Vue3】从零开始编写项目
  • 今日总结:雪花算法,拉取在线用户
  • 深入理解Linux网络(二):UDP接收内核探究
  • tg小程序前端-dogs前端源码分析
  • mongodb数据导出与导入
  • 【20】读感 - 架构整洁之道(二)
  • 基于springboot+vue+uniapp的农场管理系统小程序
  • 77. Combinations
  • Angular2开发踩坑系列-生产环境编译
  • CSS实用技巧干货
  • java第三方包学习之lombok
  • jquery cookie
  • Linux中的硬链接与软链接
  • Magento 1.x 中文订单打印乱码
  • Netty 4.1 源代码学习:线程模型
  • Node 版本管理
  • php的插入排序,通过双层for循环
  • Promise面试题2实现异步串行执行
  • Redis 懒删除(lazy free)简史
  • socket.io+express实现聊天室的思考(三)
  • 阿里云Kubernetes容器服务上体验Knative
  • 翻译 | 老司机带你秒懂内存管理 - 第一部(共三部)
  • 更好理解的面向对象的Javascript 1 —— 动态类型和多态
  • 关于 Linux 进程的 UID、EUID、GID 和 EGID
  • 函数式编程与面向对象编程[4]:Scala的类型关联Type Alias
  • 基于Vue2全家桶的移动端AppDEMO实现
  • 前嗅ForeSpider采集配置界面介绍
  • 事件委托的小应用
  • 通信类
  • 无服务器化是企业 IT 架构的未来吗?
  • 想使用 MongoDB ,你应该了解这8个方面!
  • 协程
  • 中文输入法与React文本输入框的问题与解决方案
  • d²y/dx²; 偏导数问题 请问f1 f2是什么意思
  • const的用法,特别是用在函数前面与后面的区别
  • ​必胜客礼品卡回收多少钱,回收平台哪家好
  • ‌前端列表展示1000条大量数据时,后端通常需要进行一定的处理。‌
  • # SpringBoot 如何让指定的Bean先加载
  • #我与Java虚拟机的故事#连载17:我的Java技术水平有了一个本质的提升
  • (+3)1.3敏捷宣言与敏捷过程的特点
  • (10)Linux冯诺依曼结构操作系统的再次理解
  • (14)学习笔记:动手深度学习(Pytorch神经网络基础)
  • (19)夹钳(用于送货)
  • (Arcgis)Python编程批量将HDF5文件转换为TIFF格式并应用地理转换和投影信息
  • (带教程)商业版SEO关键词按天计费系统:关键词排名优化、代理服务、手机自适应及搭建教程
  • (附源码)springboot 智能停车场系统 毕业设计065415
  • (教学思路 C#之类三)方法参数类型(ref、out、parmas)