Spring Security 自定义User 出现com.*.

2019-09-25  本文已影响0人  扯淡巴

1、问题描述

在使用Spring Security 过程中
① MyUser 继承自 org.springframework.security.core.userdetails.User
② loadUserByUsername 自定义方法中已经返回了,自定义的MyUser
③ 使用(MyUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal()

出现异常:
com.**.MyUser cannot be cast to com.**.MyUser

2、解决方案

去除你的热部署 devtool
参考链接:https://www.jianshu.com/p/25be7b0abe5a
反向操作一遍,之后,问题自然而解。

上一篇 下一篇

猜你喜欢

热点阅读