I am reading official get started article about how to start spring-jms application
https://spring.io/guides/gs/messaging-jms/
@EnableJms triggers the discovery of methods annotated with @JmsListener, creating the message listener container under the covers.
But my application sees @JmsListener
methods without @EnableJms
annotation.
Maybe something else force spring search the @EnableJms
methods. I want to know it.
project srtucture:
Listener:
@Component
public class Listener {
@JmsListener(destination = "my_queue_new")
public void receive(Email email){
System.out.println(email);
}
@JmsListener(destination = "my_topic_new", containerFactory = "myFactory")
public void receiveTopic(Email email){
System.out.println(email);
}
}
RabbitJmsApplication:
@SpringBootApplication
//@EnableJms I've commented it especially, behaviour was not changed.
public class RabbitJmsApplication {
public static void main(String[] args) {
SpringApplication.run(RabbitJmsApplication.class, args);
}
@Bean
public RMQConnectionFactory connectionFactory() {
return new RMQConnectionFactory();
}
@Bean
public JmsListenerContainerFactory<?> myFactory(DefaultJmsListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
// This provides all boot's default to this factory, including the message converter
configurer.configure(factory, connectionFactory);
// You could still override some of Boot's default if necessary.
factory.setPubSubDomain(true);
return factory;
}
}
@EnableJms
annotation on the class path will trigger theJmsAnnotationDrivenConfiguration
from Spring Boot. Which will automatically register the needed components. – Tufthunter