Cannot construct instance of `org.springframework.security.core.authority.SimpleGrantedAuthority`

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cannot construct instance of `org.springframework.security.core.authority.SimpleGrantedAuthority`相关的知识,希望对你有一定的参考价值。

参考技术A 错误描述
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of org.springframework.security.core.GrantedAuthority (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information

然后在redis的反序列化使用Jackson2JsonRedisSerializer反序列化,在里面配置ObjectMapper

配置中加上

最后说下jackson+redis序列化会根据get方法自动序列没有此字段的序列化字段出来,SimpleGrantedAuthority中只有role字段 ,没有authority字段,有getAuthority方法赋值role值。

其实就是在spring security 权限集合反序列化失败

这时候我们就需要自定义一个反序列化的类

同时加上一个注解 自定义解析即可生效
@JsonDeserialize(using = CustomAuthorityDeserializer.class)

RuntimeError: Cannot run in multiple processes: IOLoop instance has already been initialized. You ca

解决方法:

settings中的debug改为false,或者注释掉

参照:

https://stackoverflow.com/questions/32521122/cannot-run-in-multiple-processes-ioloop-instance-has-already-been-initialized

以上是关于Cannot construct instance of `org.springframework.security.core.authority.SimpleGrantedAuthority`的主要内容,如果未能解决你的问题,请参考以下文章

Ajax提交数据SpringBoot后台报错“HttpMessageNotReadableException: JSON parse error: Cannot construct instance“

日常Exception第二十二回:构造函数异常Cannot construct instance of `xx.xxx` (no Creators, like default construct

异常Cannot construct instance of `com.facebook.presto.jdbc.internal.client.QueryResults`, problem: s(代

__construct 的可见性

FlinkFlink SQL Cannot instantiate user function cannot assign instance LinkedMap FlinkKafkaConsum

RuntimeError: Cannot run in multiple processes: IOLoop instance has already been initialized. You ca