解决springboot+spring security中:There is no PasswordEncoder mapped for the id "null"

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{

	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http.authorizeRequests().antMatchers("/css/**","/js/**","/fonts/**","/index").permitAll()
		.antMatchers("/users/**").hasRole("ADMIN")
//		.antMatchers(HttpMethod.POST, "/users").hasRole("ADMIN")
		.and()
		.formLogin()
		.loginPage("/login")
		.failureUrl("/login-error");
	}
	
	@Autowired
	public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
//		auth.inMemoryAuthentication().withUser("mch").password("123").roles("ADMIN");
		//解决There is no PasswordEncoder mapped for the id "null"
		auth.inMemoryAuthentication().withUser("mch").password(passwordEncoder().encode("123")).roles("ADMIN");
	}
	//为了解决There is no PasswordEncoder mapped for the id "null"
	@Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}

参考:https://blog.csdn.net/qinkaiyuan94/article/details/80565904

你可能感兴趣的:(解决springboot+spring security中:There is no PasswordEncoder mapped for the id "null")