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:
- 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?)
- 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
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' :
It is related to AsyncAnnotationBeanPostProcessor which tries to instantiate taskExecutor for
@Asyncannotated 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:
@Asyncannotation and we don't have@EnableAsyncanywhere 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:
@Asyncin 4.2.x but works in 4.1.xReferenced from: commits 2a3bf69