【问题标题】:Disable Spring Cloud Stream Rabbit for tests禁用 Spring Cloud Stream Rabbit 进行测试
【发布时间】:2019-12-27 06:30:00
【问题描述】:

我用:

    <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 spring-rabbit


    【解决方案1】:

    在 pom.xml 中添加 spring-cloud-stream-test-support

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

    【讨论】:

      【解决方案2】:

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

      @SpringBootTest
      @ImportAutoConfiguration(exclude = RabbitServiceAutoConfiguration.class)
      

      【讨论】:

      【解决方案3】:

      尝试以下操作:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-16
        • 2017-12-25
        • 2022-07-20
        • 2017-03-24
        • 2018-11-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多