Bootstrap

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会知道是明文校验

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;