使用 com.rabbitmq.http.client.Client 从 Java 向 RabbitMQ 发送消息

时间:2021-05-08 10:57:25

标签: java spring rabbitmq spring-rabbit

我正在尝试从 Java 服务向 RabbitMQ 发送消息。

我正在使用一些 Java RabbitMQ 客户端库并尝试运行以下代码:

    private static Client setAcceptAllSSL() throws Exception {
        TrustStrategy acceptingTrustStrategy = (cert, authType) -> true;
        SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
        requestFactory = new HttpComponentsRestTemplateConfigurator(sslsf,sslContext);
        return new Client(new ClientParameters().url(url).username(username).password(password).restTemplateConfigurator(requestFactory));
    }

最后一行(Client objectinitialization),抛出如下错误:

<块引用>

java.lang.NoClassDefFoundError: org/springframework/http/converter/json/Jackson2ObjectMapperBuilder

我想我的 pom.xml 或 Spring 版本中可能缺少某些内容。但是,我找不到任何丢失的导入/库/版本问题。

请帮忙:)

1 个答案:

答案 0 :(得分:1)

在 pom.xml 中添加这个 jackson 依赖:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>${jackson.databind-version}</version>
</dependency>
相关问题