TaskExecutionAutoConfiguration
currently only take single TaskDecorator
bean.
This is because there is no implementation that represents multiple TaskDeorator
s. (e.g.: CompositeTaskDecorator
).
I handle this by creating CompositeTaskDecorator
:
public class CompositeTaskDecorator implements TaskDecorator {
private List<TaskDecorator> taskDecorators = new ArrayList<>();
public CompositeTaskDecorator(Collection<? extends TaskDecorator> taskDecorators) {
this.taskDecorators.addAll(taskDecorators);
}
public CompositeTaskDecorator(TaskDecorator... taskDecorators) {
this.taskDecorators.addAll(Arrays.asList(taskDecorators));
}
public boolean add(TaskDecorator taskDecorator) {
return this.taskDecorators.add(taskDecorator);
}
@Override
public Runnable decorate(Runnable runnable) {
for (TaskDecorator taskDecorator : this.taskDecorators) {
runnable = taskDecorator.decorate(runnable);
}
return runnable;
}
}
I believe it is pretty common to have usecases to apply multiple TaskDecorators; so, it is nice if CompositeTaskDecorator
is available in either spring or spring-boot.
Then, if such class is available, TaskExecutionAutoConfiguration
(TaskExecutorBuilder
) can detect multiple task decorators.
TaskDecorator taskDecorator(ObjectProvider<TaskDecorator> taskDeorators) {
return new CompositeTaskDecorator(taskDeorators.orderedStream().collect(Collectors.toList()));
}
Comment From: snicoll
I've moved that suggestion to Spring Framework. If it turns out this gets added in the core container, we can make the necessary changes in Spring Boot.
Comment From: cptully
This is an old issue, any movement? I'm glad I googled, because I was about to run into the exact issue solved by this PR!
Comment From: sbrannen
This is an old issue, any movement?
We'll discuss it within the team.
Comment From: cptully
Great!
Comment From: snicoll
Closing in favor of PR #23692