0

我正在编写使用很少工人的 webapp。我决定使用 JMS ActiveMQ 在它们之间进行通信。我的问题是,当我将工作人员配置更改为 java 时(当配置在 xml 中时,我无法运行 jar)当消息返回到 webapp 时出现问题:

[org.springframework.jms.listener.DefaultMessageListenerContainer#4-3] WARN  o.s.j.l.DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

早些时候我有这样的配置(在xml中):

<jms:listener-container>
            <jms:listener destination="sample.reply" ref="sampleMessageListener" />
</jms:listener-container>

一切正常,然后在我的工作人员中,我将其更改为如下配置:

@Bean
    public static DefaultMessageListenerContainer configureListener() {
            DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
            container.setDestinationName("xxxxx.xxxxx");
            container.setMessageListener(context.getBean("someBean"));
            container
                            .setConnectionFactory(context.getBean(ConnectionFactory.class));
            container.setConcurrency("5-10");
            return container;
    }

这也有效,但是当我将消息发送回 webapp 时,我看到丢失上下文的问题。

4

0 回答 0