Skip to content

Async configuration ignores applicationTaskExecutor when EnableScheduling is enabled #15748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* {@link EnableAutoConfiguration Auto-configuration} for {@link TaskExecutor}.
*
* @author Stephane Nicoll
* @author Camille Vienot
* @since 2.1.0
*/
@ConditionalOnClass(ThreadPoolTaskExecutor.class)
Expand All @@ -48,6 +49,8 @@ public class TaskExecutionAutoConfiguration {
*/
public static final String APPLICATION_TASK_EXECUTOR_BEAN_NAME = "applicationTaskExecutor";

public static final String ASYNC_TASK_EXECUTOR_BEAN_NAME = "taskExecutor";

private final TaskExecutionProperties properties;

private final ObjectProvider<TaskExecutorCustomizer> taskExecutorCustomizers;
Expand Down Expand Up @@ -79,7 +82,7 @@ public TaskExecutorBuilder taskExecutorBuilder() {
}

@Lazy
@Bean(name = APPLICATION_TASK_EXECUTOR_BEAN_NAME)
@Bean(name = { APPLICATION_TASK_EXECUTOR_BEAN_NAME, ASYNC_TASK_EXECUTOR_BEAN_NAME })
@ConditionalOnMissingBean(Executor.class)
public ThreadPoolTaskExecutor applicationTaskExecutor(TaskExecutorBuilder builder) {
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.test.util.ReflectionTestUtils;

Expand All @@ -49,6 +50,7 @@
* Tests for {@link TaskExecutionAutoConfiguration}.
*
* @author Stephane Nicoll
* @author Camille Vienot
*/
public class TaskExecutionAutoConfigurationTests {

Expand Down Expand Up @@ -151,6 +153,21 @@ public void enableAsyncUsesAutoConfiguredOneByDefault() {
});
}

@Test
public void enableAsyncUsesAutoConfiguredOneByDefaultEvenThoughSchedulingIsConfigured() {
this.contextRunner
.withPropertyValues("spring.task.execution.thread-name-prefix=task-test-")
.withConfiguration(
AutoConfigurations.of(TaskSchedulingAutoConfiguration.class))
.withUserConfiguration(AsyncConfiguration.class,
SchedulingConfiguration.class, TestBean.class)
.run((context) -> {
TestBean bean = context.getBean(TestBean.class);
String text = bean.echo("something").get();
assertThat(text).contains("task-test-").contains("something");
});
}

private ContextConsumer<AssertableApplicationContext> assertTaskExecutor(
Consumer<ThreadPoolTaskExecutor> taskExecutor) {
return (context) -> {
Expand Down Expand Up @@ -208,6 +225,12 @@ static class AsyncConfiguration {

}

@Configuration
@EnableScheduling
static class SchedulingConfiguration {

}

static class TestBean {

@Async
Expand Down