java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
解决方案:
此异常是因为引入的SpringSecurity依赖是5.X版本的,这个版本需要提供一个PasswordEncoder的实例,否则就会报异常
public class MyPasswordEncoder implements PasswordEncoder { @Override public String encode(CharSequence charSequence) { return charSequence.toString(); } @Override public boolean matches(CharSequence charSequence, String s) { return s.equals(charSequence.toString()); } }
使用实例MyPasswordEncoder()
@Override protected void configure(AuthenticationManagerBuilder builder) throws Exception { builder.inMemoryAuthentication() // 在内存中完成账号密码的检查 .passwordEncoder(new MyPasswordEncoder()) .withUser("tom") // 指定账号 .password("123") // 指定密码 .roles("ADMIN") // 指定当前用户的角色