我正在编写使用很少工人的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时,我发现丢失上下文的问题。