严重:Servlet.service() for servlet [springmvc] in context with path [] threw exception
spring security无法获取SecurityContextHolder.getContext().getAuthentication()
我遇到该问题的主要原因是import导入的包,错误地导成了本地user
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
替换成这个user即可
import org.springframework.security.core.userdetails.User;