Spring 启动应用程序以从 RabbitMQ 使用时出现异常

Exception when Spring Boot app to consume from RabbitMQ

我的 springboot 应用程序中有以下代码

@Bean
    public IntegrationFlow amqpInbound(ConnectionFactory connectionFactory) {
        return IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, "aName"))
                .handle(m -> System.out.println(m.getPayload()))
                .get();
    }

当我 运行 启动应用程序时,出现以下异常!

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'amqpInbound' defined in class path resource [com/mitchell/csg/acsstatefarmedibundler/filesHandler/FileMonitorBeanRegistry.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'amqpInbound' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper: method ()V not found

这是我的pom.xml。

 <dependency>
          <groupId>org.springframework.integration</groupId>
          <artifactId>spring-integration-amqp</artifactId>
          <version>5.1.0.RELEASE</version>
      </dependency>

我是否遗漏了任何其他依存关系?

既然你提到了Spring引导,那么覆盖依赖的版本是没有意义的。现在看起来您的 Spring 引导版本不是 2.1,这使得所有依赖项都与提到的 Spring 集成版本兼容。

嗯,简单的答案是从 spring-integration-amqp 依赖项中删除一个版本并完全依赖 Spring 引导管理。