1

为了在 Spring Boot 应用程序中使用 Spring Integration Amqp,我需要包含哪些依赖项?

Spring Boot 版本为 2.0.5。我目前的依赖是spring-boot-starter-integrationspring-integration-amqp

错误消息是类SimpleMessageListenerContainerAmqpInboundChannelAdapter在类路径中找不到。

更新:我的 build.gradle 条目——

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
    }
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-integration')
    compile('org.springframework.boot:spring-boot-starter-amqp')
    compile('org.springframework.integration:spring-integration-amqp')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
4

2 回答 2

1

添加此依赖项:

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>

你确定你有这个吗?:

<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-amqp</artifactId>
于 2018-09-25T13:23:56.187 回答
1

我必须添加以下依赖项来解决有问题的类(列表中的最后一个做到了,使用最新的 spring initalizr,spring-boot 2.0.5)

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-amqp')
    implementation('org.springframework.boot:spring-boot-starter-integration')
    testImplementation('org.springframework.boot:spring-boot-starter-test')

    compile 'org.springframework.integration:spring-integration-amqp'
}

公平地说,这个答案已经给出,只是不适合 gradle。

我在 linux 机器上使用 gradle 4.10.2,带有选项的 spring-boot initialzrRabbitMQSpring-Integration. 以下是更改后的文件:

构建.gradle

buildscript {
    ext {
        springBootVersion = '2.0.5.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    implementation('org.springframework.boot:spring-boot-starter-amqp')
    implementation('org.springframework.boot:spring-boot-starter-integration')
    testImplementation('org.springframework.boot:spring-boot-starter-test')

    compile 'org.springframework.integration:spring-integration-amqp'
}

示例 12.2.1 使用 Spring Integration 文档中的 Java 配置进行配置的实现:

package com.example.integrationamqp;

import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter;
import org.springframework.integration.amqp.inbound.AmqpInboundGateway;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;



@SpringBootApplication
public class IntegrationAmqpApplication {

     public static void main(String[] args) {
        new SpringApplicationBuilder(IntegrationAmqpApplication.class)
                .web(WebApplicationType.NONE)
                .run(args);
    }

    @Bean
    public MessageChannel amqpInputChannel() {
        return new DirectChannel();
    }

    @Bean
    public AmqpInboundChannelAdapter inbound(SimpleMessageListenerContainer listenerContainer,
                                             @Qualifier("amqpInputChannel") MessageChannel channel) {
        AmqpInboundChannelAdapter adapter = new AmqpInboundChannelAdapter(listenerContainer);
        adapter.setOutputChannel(channel);
        return adapter;
    }

    @Bean
    public SimpleMessageListenerContainer container(ConnectionFactory connectionFactory) {
        SimpleMessageListenerContainer container =
                new SimpleMessageListenerContainer(connectionFactory);
        container.setQueueNames("foo");
        container.setConcurrentConsumers(2);
        // ...
        return container;
    }

    @Bean
    @ServiceActivator(inputChannel = "amqpInputChannel")
    public MessageHandler handler() {
        return new MessageHandler() {

            @Override
            public void handleMessage(Message<?> message) throws MessagingException {
                System.out.println(message.getPayload());
            }

        };
    }
}
于 2018-10-02T14:22:27.380 回答