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
{{ message }}
Repository navigation
Regression: AsyncAnnotationBeanPostProcessor fails on startup when encountering ambiguous TaskExecutor beans [SPR-13720] #18293
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?
Juergen Hoeller the previous behaviour was to create the advisor with a null executor which in turn would create a default instance. Is there a reason why you took the decision to throw an exception instead. Maybe a warning would be better?
Class that bootstraps our context extends DelegatingWebMvcConfiguration (but we don't touch configureAsyncSupport method) and web app initializer class implements WebApplicationInitializer.
I've searched our project and some projects that we depend on looking for @EnableAsync and I've found nothing.
AsyncAnnotationBeanPostProcessor is supposed to leniently handle such a scenario, simply falling back to an internal default executor then - which might not even apply if no @Async is being used in the first place. In other words, it should be able to exist next to @Scheduled processing within the same application even if no @Async execution setup is available.
I've changed the exception to an info log message (without exception), just indicating that async annotation processing will use an internal default executor due to no corresponding bean found.
Activity
spring-projects-issues commentedon Nov 25, 2015
Stéphane Nicoll commented
Can you tell us a bit more about your project? The post processor won't be invoked unless
@EnableAsyncis added to some configuration class.spring-projects-issues commentedon Nov 25, 2015
Stéphane Nicoll commented
Juergen Hoeller the previous behaviour was to create the advisor with a null executor which in turn would create a default instance. Is there a reason why you took the decision to throw an exception instead. Maybe a warning would be better?
spring-projects-issues commentedon Nov 25, 2015
Piotr Leśniak commented
We don't have
@EnableAsyncimplicitly declared in any of out@Configurationclasses. Could it come transitively from some other spring project?We don't use websockets. We have some
@Scheduledmethods.Here is complete list of spring projects with versions which we include:
Class that bootstraps our context extends
DelegatingWebMvcConfiguration(but we don't touchconfigureAsyncSupportmethod) and web app initializer class implementsWebApplicationInitializer.I've searched our project and some projects that we depend on looking for
@EnableAsyncand I've found nothing.spring-projects-issues commentedon Nov 25, 2015
Juergen Hoeller commented
AsyncAnnotationBeanPostProcessoris supposed to leniently handle such a scenario, simply falling back to an internal default executor then - which might not even apply if no@Asyncis being used in the first place. In other words, it should be able to exist next to@Scheduledprocessing within the same application even if no@Asyncexecution setup is available.I've changed the exception to an info log message (without exception), just indicating that async annotation processing will use an internal default executor due to no corresponding bean found.
Juergen
spring-projects-issues commentedon Nov 25, 2015
Juergen Hoeller commented
This is available in the latest
4.2.4.BUILD-SNAPSHOTin the meantime. Please give it a try and let me know whether it works for you...Juergen