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

1190 ワード

@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