找不到用户
org.springframework.security.core.userdetails.UsernameNotFoundException: admin
你需要重写这个接口
public interface UserDetailsService { UserDetails loadUserByUsername(String var1) throws UsernameNotFoundException; }
-===============================================================
重写如下
@Override public UserDetails loadUserByUsername(String phone) throws UsernameNotFoundException{ User user = userService.findByPhone(phone); if(user == null) { throw new UsernameNotFoundException("Invalid User"); } else { Set<GrantedAuthority> grantedAuthorities = user.getRoles() .stream() .map(role -> new SimpleGrantedAuthority(role.getName())) .collect(Collectors.toSet()); return new org .springframework .security .core .userdetails .User(user.getPhone(), user.getPassword(), grantedAuthorities); } }