Spring Security使用:There is no PasswordEncoder mapped for the id null错误

洼地云 ai-quyi.png

使用Spring Security作为身份验证和授权的框架时,用户登录报错。

一、环境信息

  • SpringBoot: 2.7.3;
  • Spring Security: 2.7.3;

二、错误信息

错误信息如下:

There is no PasswordEncoder mapped for the id null

三、解决

出错原因: Spring Security需要定义一个PasswordEncoder来处理用户密码。如果你不想对密码配置加密,你可以用NoOpPasswordEncoder来处理。

@EnableWebSecurity
public class WebSecurityConfigurer {
    /**
     * 指定加密方式
     */
    @Bean
    public PasswordEncoder passwordEncoder() {
        // 使用BCrypt加密密码
        return new BCryptPasswordEncoder();
    }
}
赞(1)
未经允许禁止转载:优米格 » Spring Security使用:There is no PasswordEncoder mapped for the id null错误

评论 抢沙发

合作&反馈&投稿

商务合作、问题反馈、投稿,欢迎联系

广告合作侵权联系

登录

找回密码

注册