Skip to content

Regression: AsyncAnnotationBeanPostProcessor fails on startup when encountering ambiguous TaskExecutor beans [SPR-13720] #18293

Closed
@spring-projects-issues

Description

@spring-projects-issues

Piotr Leśniak opened SPR-13720 and commented

After upgrading spring-core from 4.1.5.RELEASE to 4.2.3.RELEASE context of our applications failed to start. The problem is with too many beans qualifying to 'taskExecutor' :

java.lang.IllegalStateException: More than one TaskExecutor bean exists within the context, and none is named 'taskExecutor'. Mark one of them as primary or name it 'taskExecutor' (possibly as an alias); or specify the AsyncConfigurer interface and implement getAsyncExecutor() accordingly ...
Caused by: 
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.core.task.TaskExecutor] is defined: expected single matching bean but found 4: clientOutboundChannelExecutor,messageBrokerTaskScheduler,clientInboundChannelExecutor,brokerChannelExecutor

It is related to AsyncAnnotationBeanPostProcessor which tries to instantiate taskExecutor for @Async annotated methods in setBeanFactory method.

The fix is easy, it requires only to create new bean named 'taskExecutor' or mark one of existing with @Primary.

However this bug is a pain for following reasons:

  1. Neither of the existing task executors in context (clientOutboundChannelExecutor,messageBrokerTaskScheduler,clientInboundChannelExecutor,brokerChannelExecutor) is created by us - all of them comes from some others spring libraries (I think messaging and websockets?)
  2. We don't use @Async annotation and we don't have @EnableAsync anywhere in our code.

Is there a way to disable AsyncAnnotationBeanPostProcessor from registering and creating taskExecutor?

Also, a logic in instantiating taskExecutor is a bit odd to me - maybe throwing exception when there are many Beans implementing TaskExecutor and no bean with name "taskExecutor" is not a good behaviour?


Affects: 4.2 GA

Issue Links:

Referenced from: commits 2a3bf69

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions