spring_security登录demo
1.在配置文件中关联登录service
```
security:authentication-manager
<security:authentication-provider user-service-ref="userService">
<security:password-encoder ref="passwordEncoder"></security:password-encoder>
</security:authentication-provider>
</security:authentication-manager>
```
2.在service中新建service类继承UserDetailsService类,重写loadUserByUsername方法
```
@Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
private SysUserDao sysUserDao;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
SysUser sysUser = sysUserDao.findByName(username);
if (sysUser != null) {
Set<GrantedAuthority> set = new HashSet<>();
GrantedAuthority grantedAuthority = new SimpleGrantedAuthority("ROLE_USER");
set.add(grantedAuthority);
UserDetails user = new User(username, sysUser.getPassword(), set);
return user;
}
return null;
}
}
```