欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > SpringSecurity:There is no PasswordEncoder mapped for the id “null“

SpringSecurity:There is no PasswordEncoder mapped for the id “null“

2025/2/3 7:45:13 来源:https://blog.csdn.net/Brave_heart4pzj/article/details/145394002  浏览:    关键词:SpringSecurity:There is no PasswordEncoder mapped for the id “null“

文章目录

  • 一、情景说明
  • 二、分析
  • 三、解决

一、情景说明

在整合SpringSecurity功能的时候
我先是去实现认证功能
也就是,去数据库比对用户名和密码

相关的类:

UserDetailsServiceImpl implements UserDetailsService	用于SpringSecurity查询数据库
LoginUser implements UserDetails	用于封装SpringSecurity的用户信息及权限信息
SysUser		对应数据库的实体类

表数据
在这里插入图片描述
可以看出,密码是123

当我用test,123登陆时,就包这个错误

二、分析

此时,我们没有增加SecurityConfig配置类,所以,没给容器注入PasswordEncoder对应的实现类
所以,SpringSecurity在进行用户认证的时候,密码对应不上。

三、解决

1、直接给SpringBoot容器注入BCryptPasswordEncoder密码加密解析类。
2、在数据的密码设置改成:{noop}123,加个{noop}前缀,则SpringSecurity会知道是明文校验

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com