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

后端 未结 7 1596
梦毁少年i
梦毁少年i 2020-12-06 04:50

I am trying Spring 3\'s @Scheduled annotation . Here is my configuration (app.xml) :




        
相关标签:
7条回答
  • 2020-12-06 04:53

    In my case, this was caused by switching versions, thereby in the output file location there are multiple version of jars (and therefore each jar contains a AnnotationBean):

    2018-02-19 13:38:44,913 [RMI TCP Connection(3)-127.0.0.1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Only one ScheduledAnnotationBeanPostProcessor may exist within the context.
    Offending resource: URL [jar:file:/C:/.../lib/xxx-2.0.jar!/META-INF/spring/xxx.xml]
    

    while I'm using 1.0 in this case. So I have to manually delete C:/.../lib/xxx-2.0.jar in this location, and I'm able to see xxx-1.0.jar is also in this directory. After the manual deletion, it works normally.

    0 讨论(0)
  • 2020-12-06 04:53

    That error, about

    Only one AsyncAnnotationBeanPostProcessor may exist within the context
    

    , can appear in one more case. I do not insist, that that must help you, maybe you really have some complicated problem, described in other posts, but no one of them helped me.

    What did help, was simple

    mvn clean
    

    , for the project somehow had created some duplicated files and those caused the problem. And a simple clean had... ehm... cleaned them.

    That situation, for example, can happen after a merge with a branch with a higher version of the project.

    0 讨论(0)
  • 2020-12-06 04:59

    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.

    0 讨论(0)
  • 2020-12-06 05:08

    I had this problem when I copied applicationContext.xml and created new one called applicationContextAdditional.xml. I didn't try to find the reason, but both contained namespace

    <bean ...
        xmlns:task="http://www.springframework.org/schema/task"
        ...
        xsi:schemaLocation="
       http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd" >
    
        ...
    
    </bean>
    

    when I removed the namespace from the second one my problem was solved. Maybe it helps someone.

    0 讨论(0)
  • 2020-12-06 05:10

    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).

    0 讨论(0)
  • 2020-12-06 05:14

    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/>
    
    0 讨论(0)
提交回复
热议问题