---
title: "Spring Security Oauth2.0 报错java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id \"null\""
date: 2019-01-07 16:55:46
categories: Spring Security
tags:
- 报错
- spring
- password
- security
- oauth2.0
- IllegalArgumentException
- PasswordEncoder
- mapped
---
Spring Security Oauth2.0 报错java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
原因:认证server里的auth.inMemoryAuthentication()里的密码不能直接写,需要加上BCryptPasswordEncoder的encode处理。修正后如下:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// auth.parentAuthenticationManager(authenticationManager)
auth.inMemoryAuthentication()
.withUser("john").password(passwordEncoder().encode("123")).roles("USER");
}
@Bean
public BCryptPasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}