禁用 Spring Cloud Stream Rabbit 进行测试

Disable Spring Cloud Stream Rabbit for tests

我使用:

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
        <version>3.0.1.RELEASE</version>
    </dependency>

我需要禁用 Rabbit 来测试应用程序。我试过这个:

spring:
    cloud:
       config:
           enabled: false
           discovery:
               enabled: false

没用。

我需要做什么来阻止 Rabbit 组件启动?

对于 Spring Cloud Stream,没有像 disable 这样的选项。 据我所知,防止 Spring Cloud Stream 在测试环境中启动的唯一方法是排除适当的 Binder 自动配置。在你的情况下,我们谈论 RabbitServiceAutoConfiguration:

@SpringBootTest
@ImportAutoConfiguration(exclude = RabbitServiceAutoConfiguration.class)

将 spring-cloud-stream-test-support 添加到 pom.xml

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-stream-test-support</artifactId>
    <version>3.0.1.RELEASE</version>
    <scope>test</scope>
</dependency>

尝试以下操作:

@SpringBootApplication(exclude = {
        BindingServiceConfiguration.class, FunctionConfiguration.class // spring-cloud-starter-stream-rabbit
    })