今天在用spring security时遇到了There is no PasswordEncoder mapped for the id “null”的错误,参考了Canon_in_D_Major的博文https://blog.csdn.net/canon_in_d_major/article/details/79675033,在此表示感谢!
但是这里有一个坑需要注意一下,就是
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//inMemoryAuthentication 从内存中获取
auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()).withUser(“user1”).password(new BCryptPasswordEncoder().encode(“123456”)).roles(“USER”);
}
方法需要修改为public的访问权限,否则会报404错误,修改后的方法如下:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
//inMemoryAuthentication 从内存中获取
auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()).withUser(“admin”).password(new BCryptPasswordEncoder().encode(“123456”)).roles(“ADMIN”);
}

收藏 打印