引起:java.lang.IllegalStateException:可能只存在一个AsyncConfigurer

时间:2016-10-25 15:19:31

标签: spring-mvc spring-boot

我试图通过实现AsyncConfigurer来获得两个ThreadPoolTask​​Executor。

当我启动应用程序时遇到此异常:

org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.scheduling.annotation.ProxyAsyncConfiguration'的bean时出错:注入自动连接的依赖项失败;嵌套异常是java.lang.IllegalStateException:可能只存在一个AsyncConfigurer     在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)〜[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]

引起:java.lang.IllegalStateException:可能只存在一个AsyncConfigurer     在org.springframework.scheduling.annotation.AbstractAsyncConfiguration.setConfigurers(AbstractAsyncConfiguration.java:68)〜[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]

@EnableAsync
@Import({ Thread1.class, Thread2.class})
public class Test {


    public static void main(String[] args) {
        SpringApplication.run(Test.class, args);
    }
}

@Configuration
class Thread1 implements AsyncConfigurer{

    @Override
    @Bean(name="executor1")
    public Executor getAsyncExecutor() {
    }

    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        // TODO Auto-generated method stub
        return null;
    }

}
@Configuration
class Thread2 implements AsyncConfigurer{

    @Override
    @Bean(name="executor2")
    public Executor getAsyncExecutor() {
    }

    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        // TODO Auto-generated method stub
        return null;
    }
}

@RestController
@RequestMapping("/")
public class EmployeeController {

    @Autowired
    EmployeeService empService;

    @RequestMapping(value="/list/", method = RequestMethod.GET)
    public List<Employee> getEmpDetails() throws Exception {
        return empService.getALlEmpl();
    }

}
@Service
public class EmployeeService {
    @Async("executor1")
    public List<Employee> getEmpDetails(){
    }

    @Async("executor2")
    public Employee getCompanyDetail(String id){
    }

}   

有人可以看一下吗?非常感谢!

0 个答案:

没有答案