Closed
Description
We are using DelegatingSecurityContextExecutorService
to handle security annotatons in our scheduled tasks. It used to work before upgrading to Spring Boot 2.1.0 since ScheduledAnnotationBeanPostProcessor
uses ScheduledExecutorService
if it can not find any bean of type TaskScheduler.
TaskSchedulingAutoConfiguration
introduced in 2.1.0 creates a default TaskScheduler
if there is none, which makes ScheduledAnnotationBeanPostProcessor
ignore our 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);
}