综合开发

解决java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”

微信扫一扫,分享到朋友圈

解决java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”

问题描述:

使用springboot,权限管理使用spring security,使用内存用户验证,但无响应报错:

java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”

解决方式

①:

创建MyPasswordEncoder类实现PasswordEncoder,加注解  @Component

@Componentpublic class MyPasswordEncoder implementsPasswordEncoder {
@OverridepublicString encode(CharSequence charSequence) {returncharSequence.toString();
}
@Overridepublic booleanmatches(CharSequence charSequence, String s) {returns.equals(charSequence.toString());
}
}

@Overrideprotected void configure(AuthenticationManagerBuilder auth) throwsException {//如果程序报错There is no PasswordEncoder mapped for the id "null",就将该段注释添加下边代码//或者在MyPasswordEncoder类上加一个@Component注解,使它成为一个Bean
auth.inMemoryAuthentication().withUser("admin").password("123456").authorities("ADMIN_ADD","ADMIN_FIND");//自定义登录用户用户名和密码并赋予一些权限
}

②:

@Overrideprotected void configure(AuthenticationManagerBuilder auth) throwsException {//这个是使用了匿名内部类auth.inMemoryAuthentication().passwordEncoder(new MyPasswordEncoder()).withUser("lxy").password("lxy").authorities("ADMIN_ADD","ADMIN_FIND");
}

解决java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”

原文地址:https://www.cnblogs.com/think-world/p/12306217.html

疫情之下爆发的那些行业,会是“昙花一现”吗?

上一篇

携手抗“疫”,云智慧监控宝为企业提供免费IT…

下一篇

你也可能喜欢

评论已经被关闭。

插入图片

热门栏目

解决java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”

长按储存图像,分享给朋友