【Spring Security】Error:A granted authority textual representation is required —— 报错

 

Security 出错了!

 

分析:

 Debug 跑后 排查是 Security 中的 UserDetails.getAuthorities() 在创建 SimpleGrantedAuthority authority 时,所传递的授权信息是空的,导致 SimpleGrantedAuthority authority 出现异常;

 报出 A granted authority textual representation is required 异常无法登录。

 

 也就是 错误是因为 登录时 查询 权限表 有 空字段数据导致,在数据库中链表查询时,导致原本没有数据的表会查出 null 数据。

 

解决:

 在 sql 的查询字段后加上 is not null 即可进行解决。

 

 但 建议 根据 不同的 需求 将空的字段数据 填上。 比如不重要的拿 / 或 * 代替。

 

posted @ 2024-05-29 17:33  学Java的`Bei  阅读(888)  评论(0)    收藏  举报