java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
时间: 2024-05-07 21:20:52 浏览: 14
这个错误通常出现在 Spring Security 的配置中。它表示密码编码器的 ID 为 null,无法映射到任何密码编码器实现。
要解决这个问题,你需要在 Spring Security 配置中定义一个密码编码器,并将其 ID 映射到相应的实现类。
例如,如果你使用的是 BCryptPasswordEncoder,可以在配置中添加以下代码:
```
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
```
然后,将密码编码器的 ID 映射到实现类:
```
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user")
.password("$2a$10$3tFQ3tV9IqJ6jXzKbl3gjOZ4swbKjzP0C1Zd2Lz0uTbOsnXzLdLkO") // password is "password"
.roles("USER")
.and()
.passwordEncoder(passwordEncoder()); // map encoder id to implementation
}
```
这样应该就能解决这个问题了。