There is no PasswordEncoder mapped for the id "null"
@Configuration
public class MySecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
PasswordEncoder encoder=new BCryptPasswordEncoder();
String pwd=encoder.encode("123");
auth.inMemoryAuthentication().withUser("tim").password(pwd).roles("admin");
}
}
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
at org.springframework.security.crypto.password.DelegatingPasswordEncoder$UnmappedIdPasswordEncoder.matches(DelegatingPasswordEncoder.java:289) ~[spring-security-crypto-5.7.2.jar:5.7.2]
at org.springframework.security.crypto.password.DelegatingPasswordEncoder.matches(DelegatingPasswordEncoder.java:237) ~[spring-security-crypto-5.7.2.jar:5.7.2]
解决方法:
@Configuration
public class MySecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
// PasswordEncoder encoder=new BCryptPasswordEncoder();
PasswordEncoder encoder=passwordEncoder();
String pwd=encoder.encode("123");
auth.inMemoryAuthentication().withUser("tim").password(pwd).roles("admin");
}
@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
}