복붙노트

[SPRING] Spring의 @Scheduled 오류 : 컨텍스트 내에 하나의 AsyncAnnotationBeanPostProcessor 만 존재할 수 있습니다.

SPRING

Spring의 @Scheduled 오류 : 컨텍스트 내에 하나의 AsyncAnnotationBeanPostProcessor 만 존재할 수 있습니다.

나는 Spring 3의 @Scheduled 주석을 시도하고있다. 다음은 내 구성 (app.xml)입니다.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:task="http://www.springframework.org/schema/task"
  xsi:schemaLocation="
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
      "
>

  <context:component-scan base-package="destiny.web"/>  
  <context:annotation-config/>
  // other beans

  <task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>
  <task:executor  id="myExecutor"  pool-size="5"/>
  <task:scheduler id="myScheduler" pool-size="10"/>
</beans>

그리고 이것은 내 봉사 수업입니다.

@Service
public class ServiceImpl implements Service , Serializable
{
  //other injections

  @Override
  @Transactional
  public void timeConsumingJob()
  {
    try
    {
      Thread.sleep(10*1000);
    }
    catch (InterruptedException e)
    {
      e.printStackTrace();
    }
  }

  @Override
  @Scheduled(cron="* * * * * ?") 
  public void secondly()
  {
    System.err.println("secondly : it is " + new Date());
  }
}

내 일식 + junit에서 테스트 할 때 잘 작동합니다. timeConsumingJob 메서드를 테스트 할 때 secondly ()가 메시지를 계속 출력합니다.

그러나 컨테이너 (Resin / 4.0.13)에 배포하면 다음과 같이 throw됩니다.

[11-03-26 12:10:14.834] {main} org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Only one AsyncAnnotationBeanPostProcessor may exist within the context.
Offending resource: class path resource [app.xml]
 at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
 at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
 at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:72)
 at org.springframework.scheduling.config.AnnotationDrivenBeanDefinitionParser.parse(AnnotationDrivenBeanDefinitionParser.java:82)

검색 한 적이 있지만 비슷한 상황을 거의 찾지 못했습니다. 가장 기본적인 설정이라고 생각하지만 작동하지 않는 이유를 모르겠습니다.

누군가 그것을 살펴볼 수 있습니까? 고마워요!

(Spring 3.0.5, Resin 4.0.13)

------------ 업데이트 됨 ---------

내가 더 깊이 파고 나면 app.xml이 다른 XML에 의해 임포트 된 것을 발견했다. 어쩌면 이것이 작업을 만드는 이유 일 것입니다. 주석 중심이 작동하지 않을 수 있습니다.

글쎄요, 콩의 위치를 ​​재조정 한 후에도 해결되었지만 여전히 의아하게 느껴집니다. (괜찮 았기 때문에, other.xml은 app.xml에 beans가 필요하다.)

해결법

  1. ==============================

    1.애플리케이션 컨텍스트가 두 번 초기화되었지만 org.springframework.scheduling.config.AnnotationDrivenBeanDefinitionParser가 두 번 ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME Bean을 등록하는 데 실패했습니다.

    애플리케이션 컨텍스트가 두 번 초기화되었지만 org.springframework.scheduling.config.AnnotationDrivenBeanDefinitionParser가 두 번 ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME Bean을 등록하는 데 실패했습니다.

    @ContextConfiguration ( "/ path / to / applicationContext.xml")이 실수로 부모 테스트 클래스와 하위 테스트 클래스 (기본 값 inheritLocations true)에있는 단위 테스트에서이 문제가 발생했습니다.

  2. ==============================

    2.나는 우리 자신의 AsyncTaskExecutor를 구현하고 기본

    나는 우리 자신의 AsyncTaskExecutor를 구현하고 기본

    다음과 같은 항목이 있는지 확인하십시오. 예이면 작업 중 하나를 제거하십시오.

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

    3.이것은 스프링이 설정 XML에서 텍스트를 두 번 구문 분석 할 때 발생합니다.

    이것은 스프링이 설정 XML에서 텍스트를 두 번 구문 분석 할 때 발생합니다.

    ApplicationContext-root.xml과 applicationContext-where-annotation-driven-is-specififed.xml은 모두 WEB.xml의 섹션에 가져 오기 때문에 이런 일이 발생했습니다.

    WEB.xml에 applicationContext-root.xml 만 남겨두면 문제가 해결됩니다.

  4. ==============================

    4.applicationContext.xml을 복사하고 applicationContextAdditional.xml이라는 새 ApplicationContext.xml을 만들 때이 문제가 발생했습니다. 나는 그 이유를 찾으려고 노력하지 않았지만 둘 다 네임 스페이스를 포함했다.

    applicationContext.xml을 복사하고 applicationContextAdditional.xml이라는 새 ApplicationContext.xml을 만들 때이 문제가 발생했습니다. 나는 그 이유를 찾으려고 노력하지 않았지만 둘 다 네임 스페이스를 포함했다.

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

    두 번째 것에서 네임 스페이스를 제거했을 때 문제가 해결되었습니다. 어쩌면 누군가를 도울 수 있습니다.

  5. ==============================

    5.내 경우, 이것은 버전을 바꿈으로써 야기 된 출력 파일 위치에 다중 버전의 jar가 있기 때문에 발생했다. 따라서 각 jar에는 AnnotationBean이 포함되어있다.

    내 경우, 이것은 버전을 바꿈으로써 야기 된 출력 파일 위치에 다중 버전의 jar가 있기 때문에 발생했다. 따라서 각 jar에는 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]
    

    이 경우 1.0을 사용하고 있습니다. 그래서 수동으로이 위치에서 C : /.../ lib / xxx-2.0.jar을 삭제해야하며 xxx-1.0.jar도이 디렉토리에 있음을 알 수 있습니다. 수동 삭제 후에는 정상적으로 작동합니다.

  6. from https://stackoverflow.com/questions/5440429/springs-scheduled-error-only-one-asyncannotationbeanpostprocessor-may-exist by cc-by-sa and MIT license