Skip to content

Commit 2a3bf69

Browse files
committed
AsyncAnnotationBeanPostProcessor leniently handles ambiguous TaskExecutor beans
Issue: SPR-13720
1 parent 58756b0 commit 2a3bf69

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public class AsyncAnnotationBeanPostProcessor extends AbstractBeanFactoryAwareAd
6767
* The default name of the {@link TaskExecutor} bean to pick up: "taskExecutor".
6868
* <p>Note that the initial lookup happens by type; this is just the fallback
6969
* in case of multiple executor beans found in the context.
70+
* @since 4.2
7071
*/
7172
public static final String DEFAULT_TASK_EXECUTOR_BEAN_NAME = "taskExecutor";
7273

@@ -130,17 +131,16 @@ public void setBeanFactory(BeanFactory beanFactory) {
130131
}
131132
catch (NoUniqueBeanDefinitionException ex) {
132133
try {
133-
executorToUse = beanFactory.getBean(DEFAULT_TASK_EXECUTOR_BEAN_NAME, TaskExecutor.class);
134+
executorToUse = beanFactory.getBean(DEFAULT_TASK_EXECUTOR_BEAN_NAME, Executor.class);
134135
}
135136
catch (NoSuchBeanDefinitionException ex2) {
136-
throw new IllegalStateException("More than one TaskExecutor bean exists within the context, " +
137-
"and none is named 'taskExecutor'. Mark one of them as primary or name it " +
138-
"'taskExecutor' (possibly as an alias); or specify the AsyncConfigurer interface " +
139-
"and implement getAsyncExecutor() accordingly.", ex);
137+
logger.info("More than one TaskExecutor bean found within the context, and none is " +
138+
"named 'taskExecutor'. Mark one of them as primary or name it 'taskExecutor' " +
139+
"(possibly as an alias) in order to use it for async annotation processing.");
140140
}
141141
}
142142
catch (NoSuchBeanDefinitionException ex) {
143-
logger.debug("Could not find default TaskExecutor bean", ex);
143+
logger.info("No TaskExecutor bean found for async annotation processing.");
144144
// Giving up -> falling back to default executor within the advisor...
145145
}
146146
}

0 commit comments

Comments
 (0)