Spring集成会导致多个bean错误

问题描述 投票:0回答:1

我正在使用Spring Boot并尝试使用Spring集成(因为我想使用其SFTP客户端)。但我收到以下错误:

Description:
Parameter 0 of constructor in com.example.demo.service.ServiceOne required a single bean, but 2 were found:
    - applicationTaskExecutor: defined by method 'applicationTaskExecutor' in class path resource [org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfiguration.class]
    - taskScheduler: defined in null


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

我确定在为spring-integration添加依赖项后会发生错误。我尝试使用@Qualifier("applicationTaskExecutor")并创建带有@Primary批注的bean,但仍然无法运行该应用程序。如何解决?

spring-boot spring-integration
1个回答
0
投票

如错误所述,在应用程序上下文中有两个TaskExecutor bean。一个由TaskExecutionAutoConfiguration自动配置,另一个由Spring Integration为其轮询功能(实际上是TaskScheduler)自动配置。

错误描述的建议是在构造函数的@Qualifier("applicationTaskExecutor")的参数0上使用ServiceOne。您不需要@Primary bean,因为故事是关于在代码之外创建的bean。

© www.soinside.com 2019 - 2024. All rights reserved.