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
反向操作一遍,之后,问题自然而解。