Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果我没有';是否没有标记为@EnableJms注释的类?_Java_Spring_Spring Boot_Rabbitmq_Spring Jms - Fatal编程技术网

Java 如果我没有';是否没有标记为@EnableJms注释的类?

Java 如果我没有';是否没有标记为@EnableJms注释的类?,java,spring,spring-boot,rabbitmq,spring-jms,Java,Spring,Spring Boot,Rabbitmq,Spring Jms,我正在阅读关于如何启动SpringJMS应用程序的官方入门文章 @EnableJms触发用注释的方法的发现 @JmsListener,在 封面 但是我的应用程序看到的@JmsListener方法没有@EnableJms注释 也许还有别的东西迫使spring搜索@EnableJms方法。我想知道 项目结构: 听众: 兔子应用程序: @springboot应用程序 //@EnableJms我特别对其进行了评论,行为没有改变。 公共类RabbitJmsApplication{ 公共静态void m

我正在阅读关于如何启动SpringJMS应用程序的官方入门文章

@EnableJms触发用注释的方法的发现 @JmsListener,在 封面

但是我的应用程序看到的
@JmsListener
方法没有
@EnableJms
注释

也许还有别的东西迫使spring搜索
@EnableJms
方法。我想知道

项目结构:

听众: 兔子应用程序:
@springboot应用程序
//@EnableJms我特别对其进行了评论,行为没有改变。
公共类RabbitJmsApplication{
公共静态void main(字符串[]args){
run(RabbitJmsApplication.class,args);
}
@豆子
公共RMQConnectionFactory connectionFactory(){
返回新的RMQConnectionFactory();
}
@豆子
公共JmsListenerContainerFactory myFactory(默认JMSListenerContainerFactoryConfigurer配置器,ConnectionFactory ConnectionFactory){
DefaultJmsListenerContainerFactory=新的DefaultJmsListenerContainerFactory();
//这为该工厂提供了所有引导的默认设置,包括消息转换器
configurer.configure(工厂、连接工厂);
//如有必要,您仍然可以覆盖Boot的一些默认设置。
factory.setPubSubDomain(true);
返回工厂;
}
}

感谢您的反馈。这确实有点令人困惑,我创建它是为了改进示例

@EnableJms
是开始处理侦听器的框架信号,它必须是显式的,因为框架无法知道您想要使用JMS


另一方面,SpringBoot可以根据上下文为您做出默认决定。如果您有必要的位来创建
连接工厂
,它就会这样做。接下来,如果我们检测到
连接工厂可用,我们将自动启用JMS侦听器的处理。

需要启用JMS。您是否再次尝试过重建并运行应用程序。@Sangam Belose我尝试过在idea中单击“构建/重建”。现在我将尝试使无效cache@Sangam-它还在工作。如果您想帮助我,我可以与您共享所有源代码。Spring Boot检测JMS的存在并自动启用JMS处理。该语句仅适用于非Spring启动应用程序。@M.Deinum,Spring如何检测JMS的存在?
@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);
    }
}
@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;
    }
}