解决java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"

mac2024-03-31  25

解决java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"

自己弄一个:

import org.springframework.security.crypto.password.PasswordEncoder; public class MyPasswordEncoder implements PasswordEncoder { @Override public String encode(CharSequence charSequence) { return charSequence.toString(); } @Override public boolean matches(CharSequence charSequence, String s) { return s.equals(charSequence.toString()); } }

然后使用:

//在内存中配置两个用户 @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .passwordEncoder(new MyPasswordEncoder()) .withUser("admin").password("admin").roles("ADMIN","USER") .and() .withUser("abel").password("abel").roles("USER"); }

出错的原因:我没有加这个:.passwordEncoder(new MyPasswordEncoder()) 高版本的springboot是必须要加这个的

最新回复(0)