Spring 集成导致多个 beans 错误
Spring Integration causes multiple beans error
我正在使用 Spring 引导并尝试使用 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,但仍然无法 运行 应用程序。如何解决?
如错误所述,应用程序上下文中有两个 TaskExecutor
bean。
一个由 TaskExecutionAutoConfiguration
自动配置,另一个由 Spring 集成为其轮询器功能自动配置,本质上是 TaskScheduler
.
错误描述建议在构造函数的 ServiceOne
的参数 0 上使用 @Qualifier("applicationTaskExecutor")
。您不需要 @Primary
bean,因为这个故事是关于在您的代码之外创建的 bean。
我正在使用 Spring 引导并尝试使用 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,但仍然无法 运行 应用程序。如何解决?
如错误所述,应用程序上下文中有两个 TaskExecutor
bean。
一个由 TaskExecutionAutoConfiguration
自动配置,另一个由 Spring 集成为其轮询器功能自动配置,本质上是 TaskScheduler
.
错误描述建议在构造函数的 ServiceOne
的参数 0 上使用 @Qualifier("applicationTaskExecutor")
。您不需要 @Primary
bean,因为这个故事是关于在您的代码之外创建的 bean。