11月23
spring security+redis序列化失败no way to handle typed deser with setterless yet
用 security加redis写项目时一直报这个错误,说是没有set方法?我用的data注解怎么可能
这个bug找了一下午,终于找到原因了:redis序列化会查询所有以get和set开头的方法,而我的user继承了security的UserDetails,多了一个集合类型的getAuthorities方法,所有导致无法序列化,使用的是jackson的序列化器
解决办法:
加上@JsonIgnore注解设置不序列化
@JsonIgnore
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
ArrayList<NdpAuthority> grantedAuthorities = CollectionUtil.newArrayList();
if (ObjUtil.isNotEmpty(roles)) {
roles.forEach(dict -> {
String roleName = dict.getStr(CommonConstant.NAME);
NdpAuthority ndpAuthority = new NdpAuthority(roleName);
grantedAuthorities.add(ndpAuthority);
});
}
return grantedAuthorities;
}
加个属性,写个对应的set方法
来源:Heck's Blog
地址:https://www.heckjj.com/post/658/
转载时须以链接形式注明作者和原始出处及本声明,否则将追究法律责任,谢谢配合!
这个bug找了一下午,终于找到原因了:redis序列化会查询所有以get和set开头的方法,而我的user继承了security的UserDetails,多了一个集合类型的getAuthorities方法,所有导致无法序列化,使用的是jackson的序列化器
解决办法:
加上@JsonIgnore注解设置不序列化
@JsonIgnore
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
ArrayList<NdpAuthority> grantedAuthorities = CollectionUtil.newArrayList();
if (ObjUtil.isNotEmpty(roles)) {
roles.forEach(dict -> {
String roleName = dict.getStr(CommonConstant.NAME);
NdpAuthority ndpAuthority = new NdpAuthority(roleName);
grantedAuthorities.add(ndpAuthority);
});
}
return grantedAuthorities;
}
加个属性,写个对应的set方法
来源:Heck's Blog
地址:https://www.heckjj.com/post/658/
转载时须以链接形式注明作者和原始出处及本声明,否则将追究法律责任,谢谢配合!