You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow configuring a TaskExecutor even if an Executor is present
This commit updates `TaskExecutionAutoConfiguration` to permit the
auto-configuration of a `TaskExecutor` even if a user-defined `Executor`
bean is present.
Such `Executor` may have been created for totally unrelated reason, and
it may or may not be an `AsyncTaskExecutor`. The default behavior has
not changed, but this commit provides a new property,
`spring.task.execution.mode` that can be set to `force` to
auto-configure the `TaskExecutor` anyway.
Because this mode made it so that two `Executor` will be present in the
context, this commit also automatically configures an `AsyncConfigurer`
if none is present already to make sure task processing uses the
auto-configured TaskExecutor.
Closesgh-44659
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutionProperties.java
+33-1
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2012-2024 the original author or authors.
2
+
* Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -37,6 +37,11 @@ public class TaskExecutionProperties {
37
37
38
38
privatefinalShutdownshutdown = newShutdown();
39
39
40
+
/**
41
+
* Determine when the task executor is to be created.
42
+
*/
43
+
privateModemode = Mode.AUTO;
44
+
40
45
/**
41
46
* Prefix to use for the names of newly created threads.
42
47
*/
@@ -54,6 +59,14 @@ public Shutdown getShutdown() {
54
59
returnthis.shutdown;
55
60
}
56
61
62
+
publicModegetMode() {
63
+
returnthis.mode;
64
+
}
65
+
66
+
publicvoidsetMode(Modemode) {
67
+
this.mode = mode;
68
+
}
69
+
57
70
publicStringgetThreadNamePrefix() {
58
71
returnthis.threadNamePrefix;
59
72
}
@@ -209,4 +222,23 @@ public void setAwaitTerminationPeriod(Duration awaitTerminationPeriod) {
209
222
210
223
}
211
224
225
+
/**
226
+
* Determine when the task executor is to be created.
227
+
*
228
+
* @since 3.5.0
229
+
*/
230
+
publicenumMode {
231
+
232
+
/**
233
+
* Create the task executor if no user-defined executor is present.
234
+
*/
235
+
AUTO,
236
+
237
+
/**
238
+
* Create the task executor even if a user-defined executor is present.
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutorConfigurations.java
+48-6
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2012-2024 the original author or authors.
2
+
* Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfigurationTests.java
+112-17
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2012-2024 the original author or authors.
2
+
* Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
0 commit comments