title: RabbitMQ @RabbitListener annotation not working in Spring (not spring-boot)
body: <p>I am trying to implement rabbitmq in my spring-core developed application. Below is my pom.xml</p>
  
  <pre><code>    &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;5.2.6.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.rabbitmq&lt;/groupId&gt;
              &lt;artifactId&gt;amqp-client&lt;/artifactId&gt;
              &lt;version&gt;5.9.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.amqp&lt;/groupId&gt;
              &lt;artifactId&gt;spring-amqp&lt;/artifactId&gt;
              &lt;version&gt;2.2.7.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.amqp&lt;/groupId&gt;
              &lt;artifactId&gt;spring-rabbit&lt;/artifactId&gt;
              &lt;version&gt;2.2.7.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>This is my RabbitConfiguration java file</p>
  
  <pre><code>
  
  import org.springframework.amqp.core.*;
  import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
  import org.springframework.amqp.rabbit.connection.ConnectionFactory;
  import org.springframework.amqp.rabbit.core.RabbitAdmin;
  import org.springframework.amqp.rabbit.core.RabbitTemplate;
  import org.springframework.amqp.rabbit.listener.MessageListenerContainer;
  import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
  import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
  import org.springframework.amqp.support.converter.MessageConverter;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.stereotype.Component;
  
  @Configuration
  public class RabbitConfiguration {
      public static final String QUEUE_NAME="MyQueue";
      public static final String EXCHANGE_NAME="My_EXCHANGE";
  
  
      @Bean
      public ConnectionFactory connectionFactory() {
          CachingConnectionFactory connectionFactory =
                  new CachingConnectionFactory("localhost");
          return connectionFactory;
      }
  
      @Bean
      public AmqpAdmin amqpAdmin() {
          return new RabbitAdmin(connectionFactory());
      }
  
      @Bean
      public RabbitTemplate rabbitTemplate() {
          RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory());
          rabbitTemplate.setMessageConverter(jsonMessageConverter());
          return rabbitTemplate;
      }
  
      @Bean
      public Queue myQueue() {
          return new Queue(QUEUE_NAME,false);
      }
  
  
     @Bean
     MessageListenerContainer messageListenerContainer() {
          SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer();
          simpleMessageListenerContainer.setConnectionFactory(connectionFactory());
          simpleMessageListenerContainer.setQueues(myQueue());
          simpleMessageListenerContainer.setMessageListener(new RabbitMQListner());
          return simpleMessageListenerContainer;
      }
      @Bean
      public MessageConverter jsonMessageConverter(){
          return new Jackson2JsonMessageConverter();
      }
  
  }
  
  </code></pre>
  
  <p>And here is my service class from where I am trying to use the rabbit</p>
  
  <pre><code>import com.rabbitmq.client.*;
  import org.springframework.amqp.core.AmqpTemplate;
  import org.springframework.amqp.core.ExchangeTypes;
  import org.springframework.amqp.core.Message;
  import org.springframework.amqp.rabbit.annotation.*;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  import org.springframework.context.annotation.Bean;
  import org.springframework.stereotype.Component;
  
  import java.io.IOException;
  @Component
  public class MessagingService{
      public void send(String msg){
          template.convertAndSend(QUEUE_NAME,msg);
      }
  
  
      @RabbitListener(queues = "foo")
      public void receiveMessage(String car)
      {
          System.out.println("Hello"+car);
      }
      @Bean
      private ApplicationContext context(){
          return new AnnotationConfigApplicationContext(RabbitConfiguration.class);
      }
  
      @Bean
      private AmqpTemplate amqpTemplate(){
          return context().getBean(AmqpTemplate.class);
      }
  
      @Autowired
      protected AmqpTemplate template;
  
  </code></pre>
  
  <p>The send method works just fine. But the @Listener annotated method does not work. It does not listen.
  What I also tried, I created another config file and annotated with @EnableRabbit, but no benefits. Is there any secret sausage to make it working?</p>
  
  <pre><code>import org.springframework.amqp.rabbit.annotation.EnableRabbit;
  import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  @EnableRabbit
  @Configuration
  public class AppConfig extends RabbitConfiguration {
      @Bean
      public SimpleRabbitListenerContainerFactory myRabbitListenerContainerFactory() {
          SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
          factory.setConnectionFactory(connectionFactory());
          factory.setMaxConcurrentConsumers(5);
          factory.setMessageConverter(jsonMessageConverter());
          return factory;
      }
  }
  </code></pre>