【问题标题】:Spring Integration causes multiple beans errorSpring Integration 导致多个 bean 错误
【发布时间】:2020-07-07 12:58:54
【问题描述】:

我正在使用 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】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-12
      • 1970-01-01
      • 2015-05-18
      • 1970-01-01
      • 2015-04-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-21
      相关资源
      最近更新 更多