2014-07-22 4 views
2

Spring @Async에서 다른 큐 용량으로 여러 실행 프로그램 풀을 갖고 싶다면 "하나의 AsyncAnnotationBeanPostProcessor가 컨텍스트 내에 존재할 수 있습니다"오류가 발생합니다.동일한 컨텍스트에서 다중 스레드 풀 지원

아래 링크에서 나는 이것이 가능하지 않음을 관찰했습니다.

Only one AsyncAnnotationBeanPostProcessor may exist within the context

https://stackoverflow.com/questions/17367572/how-to-configure-multiple-threadpooltaskexecutors-within-the-same-application-co

http://forum.spring.io/forum/spring-projects/container/79086-multiple-executor-possible

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

다음

(스프링 통합을 사용하는 것보다 다른) 어떤 대안이 있는가 내 구성

,691,363입니다

<!- Executor A --> 
<task:annotation-driven executor="executor_A"/> 
<task:executor id="executor_A" pool-size="100"/> 

<!- Executor B --> 
<task:annotation-driven executor="executor_B"/> 
<task:executor id="executor_B" pool-size="100"/> 

아래 위의 두 가지 구성이 다른 XML 컨텍스트 파일에 정의 된 모든 소스 코드에서 동일한 응용 프로그램 컨텍스트

에로드처럼210

내 구성은, 나는 특정에 매핑하고 내가 배포 할 때 집행

@Async("executor_A") 
public void testExecutorA() 
{ 
} 



@Async("executor_B") 
public void testExecutorB() 
{ 
} 

, 나는 다음과 같은 오류를 얻을

2014년 7월 22일 09 : 41 : 26.644 [localhost-startStop-1] 오류 osweb.context.ContextLoader U : SC : TX : 컨텍스트 초기화에 실패했습니다. org.springframework.beans.factory.parsing.BeanDefinitionParsingException : 구성 문제 : Bean 정의를 가져 오지 못했습니다. URL 위치 [classpath * :/META-INF/domainconfig/* - domain-context.xml] 부적절한 리소스 : ServletContext 리소스 [/WEB-INF/spring/root-context.xml]; 중첩 예외는 org.springframework.beans.factory.parsing.BeanDefinitionParsingException : 구성 문제 : 단 하나의 AsyncAnnotationBeanPostProcessor가 컨텍스트 내에 존재할 수 있습니다. 잘못된 리소스 : URL [jar : file :/D : /tomcat/apache-tomcat-7.0.29/webapps/myapp/WEB-INF/lib/myapp-domain-1.0.0.jar!/META-INF/domainconfig /my-domain-context.xml]

감사

답변

1

당신은 더 설명하지 않은 구성이 어떻게 생겼는지하지만이 같은 맥락에서 다른 ExecutorService이 가능합니다. 포럼에 대한 마지막 링크는 실제로 the issue that implements this feature에 대한 설명과 함께 의견이 있습니다.

그냥 그것들을 정의하고 자격 특정 호출에 사용할 서비스, 같은과 @Async 주석 : 여러 일치하는 후보가있을 때, 당신은 하나 인 지정해야

@Async("myExecutor") 
public Future<Foo> handle() { ... } 

명시 적으로 아무 것도 지정되지 않은 경우 (즉, 기본값 인 서비스를 정의하는 경우) 사용됩니다.이렇게하려면, 그것을 지정 중 하나 <task:annotation-driven/> 요소 자세한 내용

<task:annotation-driven executor="myExecutor" 

또는

@EnableAsync 
@Configuration 
public class AppConfig implements AsyncConfigurer { 

    public Executor getAsynchExecutor() { ... } 
} 

확인 the documentation와.

(스프링 프레임 워크 4.1에서 AsyncConfigurer은 추가 방법이 있으므로 AsyncConfigurerSupport에서 확장하는 것이 좋습니다).

+0

응답 해 주셔서 감사합니다. 나는 주 qs에 세부 사항을 추가했습니다. – lives

+0

글쎄, 나는 이미 당신에게 대답했습니다. 'task : annotation-driven' 요소를 두 번 정의 할 수는 없습니다. 사용하려는 주 집행자와 한 번만 등록하고 다른 집행자가 필요한 경우 특수 효과에 정의하십시오. –

+0

죄송합니다 - 따라갈 수 없습니다. 다른 실행 프로그램 풀이 필요하고 @Async를 사용하여 주석으로 정의한 경우 - 해당 실행 프로그램 풀의 풀 크기는 무엇입니까? 내가 정의한 기본값이 될 것입니까? 또는 주석에서 풀 크기를 정의 할 수 있습니까? – lives

관련 문제