【问题标题】:Exception when Spring Boot app to consume from RabbitMQSpring Boot 应用程序从 RabbitMQ 使用时出现异常
【发布时间】:2019-04-23 12:54:08
【问题描述】:

我的 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:在类路径资源 [com/mitchell/csg/acsstatefarmedibundler/filesHandler/FileMonitorBeanRegistry.class] 中定义名称为“amqpInbound”的 bean 创建错误:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.integration.dsl.IntegrationFlow]:工厂方法“amqpInbound”抛出异常;嵌套异常是 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-boot rabbitmq spring-amqp spring-rabbit


    【解决方案1】:

    由于您提到了 Spring Boot,因此覆盖依赖版本是没有意义的。现在看起来你的 Spring Boot 版本不是 2.1 这使得所有依赖项都与提到的 Spring Integration 版本兼容。

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

    【讨论】:

    • 我尝试更新到 2.1,但我还有其他东西,例如 IntegrationFlows.from(s -> s.file(new File,当我更新它时失败了
    • 你不明白我的意思:当你使用 Spring Boot 时,通常不应该使用任何版本的依赖项。因此,不要将 5.1.0 添加到您的 SI AMQP 依赖项中。你不能继续使用 Boot 2.0 来做其他事情,只升级 SI 依赖项
    • `IntegrationFlows.from(s -> s.file())` 来自旧的不受支持的 SI Java DSL 扩展项目。当 Java DSL 合并到核心项目中时,它已从 API 中删除:github.com/spring-projects/spring-integration/wiki/…
    • 感谢您提供的信息,真的很有帮助。我对这些东西很陌生。我正在尝试每 30 分钟从 rabbitMq 读取数据,请您指导我如何使用 pollable 来执行此操作,或者我是否必须查看其他方式
    • 听起来与这里的原始问题无关。请考虑接受当前问题的答案,并为另一个问题提出一个新的 SO 线程。
    猜你喜欢
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-24
    • 1970-01-01
    • 2018-05-17
    • 2016-06-21
    • 2018-10-22
    相关资源
    最近更新 更多