【发布时间】:2018-01-29 11:08:35
【问题描述】:
我正在阅读有关如何启动 spring-jms 应用程序的官方入门文章
https://spring.io/guides/gs/messaging-jms/
@EnableJms 触发发现带有注释的方法 @JmsListener,在下面创建消息监听容器 封面。
但我的应用程序看到没有@EnableJms 注释的@JmsListener 方法。
也许其他东西会强制弹簧搜索@EnableJms 方法。我想知道。
项目结构:
听众:
@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 是必需的。您是否尝试过重新构建和运行应用程序。
-
@Sangam Belose 我尝试在想法中单击构建/重建。现在我将尝试使缓存无效
-
@Sangam - 它仍在工作。如果您愿意帮助我,我可以与您分享所有资源。
-
Spring Boot 检测到 JMS 的存在并自动启用 JMS 处理。该声明仅适用于非 Spring Boot 应用程序。
-
@M. Deinum,spring如何检测JMS的存在?
标签: java spring spring-boot rabbitmq spring-jms