本文介绍了春天,JMS丢失上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i'm writing webapp that uses few workers. I decide to use JMS ActiveMQ to communication between them. My problem is that when i change workers configuration to java (when config was in xml i couldn't run jar) i have problem when message returns to webapp :

2013-07-19 21:23:23.653   [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.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131) ~[spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils.currentRequestAttributes(WebApplicationContextUtils.java:281) ~[spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils.access$300(WebApplicationContextUtils.java:69) ~[spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:296) ~[spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:292) ~[spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler.invoke(AutowireUtils.java:179) ~[spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at com.sun.proxy.$Proxy52.getScheme(Unknown Source) ~[na:na]
at pl.optymalnetrasy.jms_calculate.CalculateResponseListener.getResultURL(CalculateResponseListener.java:144) ~[CalculateResponseListener.class:na]
at pl.optymalnetrasy.jms_calculate.CalculateResponseListener.onMessage(CalculateResponseListener.java:73) ~[CalculateResponseListener.class:na]
at org.springframework.jms.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:330) ~[spring-jms-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:537) ~[spring-jms-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:497) ~[spring-jms-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468) ~[spring-jms-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325) [spring-jms-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263) [spring-jms-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1096) [spring-jms-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at     org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1088) [spring-jms-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:985) [spring-jms-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at java.lang.Thread.run(Thread.java:722) [na:1.7.0_21]

我不知道响应消息回来时如何接收上下文.

I don't have any idea how to receive context back when response message come back.

推荐答案

您正试图从JMS线程访问Web资源,这是不允许的.

You are attempting to access web resources from a JMS thread and that's not allowed.

有问题的代码似乎在CalculateResponseListener.getResultURL()中.

The offending code seems to be in CalculateResponseListener.getResultURL().

您需要重新架构应用程序以避免这种情况.

You need to re-architect your application to avoid this.

这篇关于春天,JMS丢失上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 13:28