Spring's @Scheduled error : Only one AsyncAnnotationBeanPostProcessor may exist within the context Spring's @Scheduled error : Only one AsyncAnnotationBeanPostProcessor may exist within the context spring spring

Spring's @Scheduled error : Only one AsyncAnnotationBeanPostProcessor may exist within the context


The application context is being initialized twice but org.springframework.scheduling.config.AnnotationDrivenBeanDefinitionParser fails registering bean ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME second time.

I encountered this problem in unit tests where @ContextConfiguration("/path/to/applicationContext.xml") was accidentally on both the parent test class and child test class (with default value of inheritLocations true).


I have faced this once after implementing our own AsyncTaskExecutor and forgetting to remove default <task:annotation-driven/>

Check if you have something like this, if yes remove one of the task.

<task:annotation-driven executor="customAsyncTaskExecutor" scheduler="taskScheduler"/><task:annotation-driven/>


This happens when spring parses the <task:annotation-driven/> text twice in a config XML.

For me this was happening because both applicationContext-root.xml and applicationContext-where-annotation-driven-is-specififed.xml were imported in my WEB.xml in <context-param> section.

Leaving only applicationContext-root.xml in WEB.xml solved the issue.