问题: 以下2种方法在接口中调用都获取不到当前登录用户信息,但是这个方法在别的接口是可以获取到信息的
1、
SecurityContextHolder.getContext().getAuthentication()
2、
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); UserDetails userDetails = (UserDetails) authentication.getPrincipal(); String username = userDetails.getUsername();
解决:
新加入红色框框部分的代码、根据token获取当前登录用户信息