查了下发现是spring security 版本在5.0后就要加个PasswordEncoder了
在securityConfig类下加入密码加密,在数据库中存的密码也是要经过这个加密的才能
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userService()).passwordEncoder(new BCryptPasswordEncoder()); }
关于加密方法
public static void main(String[] args) { BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); //对"123456"加密 String encode = bCryptPasswordEncoder.encode("123456"); System.out.println(encode); //结果:$10$/3Ow1Sy1r/SZSNTsRTCUIO0QI1qfjk.m.J7GyDOs/BcuObL4SXLG6 } }