import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Resource
ThreadPoolTaskExecutor threadPoolTaskExecutor;
//线程池外(线程外)获取 Authentication
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//线程池里面(线程里面)使用 Authentication
//多线程处理
CompletableFuture completableFuturem = CompletableFuture.runAsync(() ->{
SecurityContextHolder.getContext().setAuthentication(authentication);
//你的业务逻辑代码 TODO
}, threadPoolTaskExecutor);
springcloud 线程池进行微服务之间调用,传递Authentication
最新推荐文章于 2024-08-04 00:11:19 发布