5

I have a web/core module project. I get this error "Only one AsyncAnnotationBeanPostProcessor may exist within the context" in my Eclipse / STS environment even though the application starts up just fine in Tomcat. I feel that this is not a real error but as it is identified it leads to problems in building my project and I want to get rid of it.

I'm pretty sure I don't import the resource that contains the task:annotation-driven executor="myExecutor" scheduler="myScheduler" multiple times, at least not explicitly.

I use Quartz but I'm not using @Scheduled, I create the scheduled beans through xml. I do use @Async throughout the application.

I have in my web project:

web.xml

    <context-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>
                  classpath:/root-context.xml
                  /WEB-INF/security.xml
              </param-value>

    </context-param>
    <servlet>
              <servlet-name>dispatcher</servlet-name>
              <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
              <init-param>
                  <param-name>dirAllowed</param-name>
                  <param-value>false</param-value>
              </init-param>
              <init-param> 
                  <param-name>contextConfigLocation</param-name>
                  <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> 
               </init-param>
              <load-on-startup>1</load-on-startup>
     </servlet>  

root-context.xml

      <import resource="classpath*:/spring/applicationContext-schedule.xml" />
      <import resource="classpath*:/spring/applicationContext-ology.xml" />
      <import resource="classpath*:/spring/applicationContext-mercadosa.xml" />
      <import resource="classpath*:/spring/applicationContext-webapp.xml" />
      <import resource="classpath*:/spring/applicationContext-ws.xml" />
      <import resource="classpath*:/spring/applicationContext-services.xml" />
      <import resource="classpath*:/spring/applicationContext.xml" />
      <import resource="classpath*:/spring/applicationContext-transaction.xml" />
      <import resource="classpath*:/spring/applicationContext-dao.xml" />
      <import resource="classpath*:/spring/applicationContext-facet.xml" />
      <import resource="classpath*:/spring/applicationContext-social.xml" />  

applicationContext-scheduled.xml

    <task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>
    <task:executor
              id="myExecutor"
              pool-size="5-10"
              queue-capacity="25"
              rejection-policy="CALLER_RUNS"/>
    <task:scheduler id="myScheduler" pool-size="3"/>
    <bean
              class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
              <property name="triggers">
              <list>
    ....
              </list>
              </property>
              <property name="quartzProperties" value="classpath:quartz.properties"/>

    [....]
    </bean>  

​ test/resources/applicationContext-test.xml both in core and web

    <task:executor id="myExecutor" pool-size="5-10" queue-capacity="25" rejection-policy="CALLER_RUNS" />  

test resources don't contain any task:annotation-driven statements.

Any suggestions?

Cheers, Marc

Marc
  • 6,773
  • 10
  • 44
  • 68
  • Did you find any solution to this problem? this is because of the context initializing multiple times in web application. I have tried to import the context-xml with the tasks only by root-context.xml, which is the main application context, but still face the issue. – wildnux Nov 27 '14 at 02:07
  • I did but I don't remember how. some ideas to consider: did you make sure that your component-scan declarations don't "overlap"? is it possible that you have a compiled project sitting in your web-target directory? – Marc Nov 27 '14 at 10:25
  • https://stackoverflow.com/a/61258683/715269 – Gangnus Apr 16 '20 at 20:46

0 Answers0