【发布时间】:2016-12-02 02:03:06
【问题描述】:
在 Spring 4 应用程序中使用 WebSphere MQ,并且在侦听 MQ 时遇到了一些问题(发送消息工作正常)。
这是我的mvc-dispatcher-servlet.xml 文件的一部分,我在其中指定了我的JmsTemplate 的信息:
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="appJmsConnectionFactory" />
<property name="defaultDestinationName" value="MQ.LISTENER.INFO.HERE" />
<property name="sessionTransacted" value="true" />
</bean>
这是我的监听类:
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
@Component
public class SpringJmsConsumer {
@Autowired
private JmsTemplate jmsTemplate;
private Destination destination;
public JmsTemplate getJmsTemplate() {
return jmsTemplate;
}
public void setJmsTemplate(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
public Destination getDestination() {
return destination;
}
public void setDestination(Destination destination) {
this.destination = destination;
}
public String receiveMessage() throws JMSException {
Message message = jmsTemplate.receive(jmsTemplate.getDefaultDestination());
// TextMessage textMessage = (TextMessage)
// jmsTemplate.receive(destination);
System.out.println("The message listened is: " + message.toString());
return message.toString();
}
}
我得到的错误:
org.springframework.jms.InvalidDestinationException: JMSMQ0003: The destination is not understood or no longer valid.; nested exception is com.ibm.msg.client.jms.DetailedInvalidDestinationException: JMSMQ0003: The destination is not understood or no longer valid. The queue or topic might have become unavailable, the application might be using an incorrect connection for the queue or topic, or the supplied destination is not of the correct type for this method.
我已经研究过如何解决这个问题,但无法找到合适的解决方案。
【问题讨论】:
标签: java spring spring-mvc message-queue