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");
}