Skip to content

TaskSchedulingAutoConfiguration prevents discovery of ScheduledExecutorService #15032

Closed
@lukas-krecan-lt

Description

@lukas-krecan-lt

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);
    }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions