Cannot pass a null GrantedAuthority collection,意思是不能传递一个空的已授权的集合,这是因为在配置类中没有配置角色,也就是没有给用户授予权限,它的权限集合是空的:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin")
.password("123")
.and()
.withUser("qxf")
.password("123");
}
解决办法就是给每个用户都配置角色,也就是授权:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin")
.password("123").roles("admin")
.and()
.withUser("qxf")
.password("123").roles("user");
}