我们用来DelegatingSecurityContextExecutorService
处理计划任务中的安全注释。它在升级到 Spring Boot 2.1.0 之前可以工作,因为如果找不到任何类型的 bean 则ScheduledAnnotationBeanPostProcessor
使用ScheduledExecutorService
TaskScheduler.
TaskSchedulingAutoConfiguration
TaskScheduler
2.1.0 中引入的如果没有则创建默认值,这使得ScheduledAnnotationBeanPostProcessor
忽略我们的ScheduledExecutorService
.
@Bean
// Ignored since Spring Boot 2.1.0
public ScheduledExecutorService scheduler() {
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
securityContext.setAuthentication(new AuthenticatedUser(loggedInUser, "root"));
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
return new DelegatingSecurityContextScheduledExecutorService(scheduledExecutorService, securityContext);
}