Prevent @RabbitListener in spring-rabbit from trying to connect to server during integration test

If the property spring.rabbitmq.listener.simple.auto-startup=false does not have effect, you might be defining your own SimpleRabbitListenerContainerFactory bean

Check how this bean is defined in the RabbitAnnotationDrivenConfiguration.rabbitListenerContainerFactory()

The SimpleRabbitListenerContainerFactoryConfigurer binds together theSimpleRabbitListenerContainerFactory and properties defined in your application.properties (among other things)

If you use your own definition, then be sure to use something along the lines of

@Bean
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
    SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, 
    ConnectionFactory connectionFactory) {

    SimpleRabbitListenerContainerFactory listenerContainerFactory =
            new SimpleRabbitListenerContainerFactory();
    containerFactoryConfigurer.configure(listenerContainerFactory, connectionFactory);

    return listenerContainerFactory;
}

I would expect the spring.rabbitmq.listener.simple.auto-startup=false to work - are you sure you're not trying to connect to Rabbit with some other code? Can you provide a DEBUG log to show the problem when that is set to false?

You can use the JUnit BrokerRunning @Rule to skip any tests that need a real RabbitMQ broker.


I've had a similar problem, but solved it with

spring.rabbitmq.listener.direct.auto-startup=false

SpringBoot version 2.2.4.RELEASE

Spring framework version 5.2.3.RELEASE