Framework & Platform/Spring

spring - 4.2.0.RELEASE AsyncAnnotationBeanPostProcessor NoUniqueBeanDefinitionException

linuxism 2015. 8. 4. 15:59


- error

Caused by: java.lang.IllegalStateException: More than one TaskExecutor bean exists within the context, and none is named 'taskExecutor'. Mark one of them as primary or name it 'taskExecutor' (possibly as an alias); or specify the AsyncConfigurer interface and implement getAsyncExecutor() accordingly.

at org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor.setBeanFactory(AsyncAnnotationBeanPostProcessor.java:135)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1597)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1565)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)

... 20 more

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.core.task.TaskExecutor] is defined: expected single matching bean but found 6: clientOutboundChannelExecutor,messageBrokerTaskScheduler,clientInboundChannelExecutor,brokerChannelExecutor,taskScheduler,defaultSockJsTaskScheduler

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:366)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:332)

at org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor.setBeanFactory(AsyncAnnotationBeanPostProcessor.java:128)

... 23 more




- resolved
* Add the bean at Spring application context configuration

@Configuration
@EnableAsync
public class AppContext extends WebMvcConfigurationSupport {
...

@Bean
public Executor taskExecutor() {
return new SimpleAsyncTaskExecutor();
}

}