连接到Websphere Mq的问题 [英] Issue in connecting to Websphere Mq

查看:84
本文介绍了连接到Websphere Mq的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用spring jms连接到Websphere MQ.

I am using spring jms to connect to Websphere MQ.

Connection names (all as an example): hostname: <Websphere ip address> http://localhost:9043
given hostname 12.123.0.12

In Resources->JMS->Queue connection Factories
name: MQDemo
JNDI name: MQDemo

2 Queues:
name: MQ.T11.UPDATE.REQUEST
JNDI name: jms/MQ.T11.UPDATE.REQUEST

name: MQ.T11.INQUIRY.REPLY
JNDI name: jms/MQ.T11.UPDATE.REQUEST

DemoMain.java

DemoMain.java

在主要方法中:

ApplicationContext ctx = new ClassPathXmlApplicationContext("app-context.xml");
    // get bean from context
    JmsMessageSender jmsMessageSender = (JmsMessageSender)ctx.getBean("jmsMessageSender");
    // send to default destination 
         jmsMessageSender.send();

JMSMessageSender.java

JMSMessageSender.java

package name: com.java.geek

 @Autowired
  private JmsTemplate jmsTemplate;


  /**
   * send text to default destination
   * @param text
   */
  @Cacheable("message")
  public void send() {
      System.out.println("in send");
        jmsTemplate.send(new MessageCreator() {
        @Override
        public Message createMessage(Session session)throws JMSException {

            System.out.println("in create message");
        Message message = (Message) session.createTextMessage("Hello JMS");
        return message;
        }
        });

    }

  public JmsTemplate getJmsTemplate()
  {
      return jmsTemplate;
  }

  public void setJmsTemplate(JmsTemplate jmsTemplate)
  {
      this.jmsTemplate = jmsTemplate;
  }

app-context.xml

app-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd">


  <context:component-scan base-package="com.java.geek" />
<bean id="amqConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
    <property name="hostName">
        <value>http://localhost:9043</value>
    </property>
    <property name="port">
        <value>1415</value>
    </property>
    <property name="queueManager">
        <value>MQDemo</value>
    </property>
    <property name="transportType">
        <value>1</value>
    </property>
</bean>

  <!-- Pooled Spring connection factory -->
  <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true"> 
        <property name="MQDemo" value="java:comp/env/jms/MQDemo" /> 
         <property name="lookupOnStartup" value="false"/>
           <property name="cache" value="true" />
           <property name="proxyInterface"  value="javax.jms.QueueConnectionFactory"/>
        <constructor-arg ref="amqConnectionFactory" />
    </bean>


  <!-- JmsTemplate Definition -->
  <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> 
        <property name="connectionFactory"><ref bean="amqConnectionFactory" />  </property> 
        <property name="pubSubDomain"><value>false</value></property> 
        <!-- <property name="defaultDestination"><ref bean="senderQueue" /></property>  -->
    </bean>  

    <!-- ======================================================= -->
  <!-- JMS Send, define default destination and JmsTemplate    -->
  <!-- ======================================================= -->

  <!-- Default Destination Queue Definition -->
  <bean id="senderQueue" class="com.ibm.mq.jms.MQQueue"> 
        <constructor-arg value="TEST" /> 
        <property name="MQ.T11.UPDATE.REQUEST" value="java:comp/env/jms/MQ.T11.UPDATE.REQUEST" /> 
    </bean> 
    <bean id="jmsMessageSender" class="com.java.geek.JmsMessageSender"> 
        <property name="jmsTemplate"><ref bean="SenderJMSTemplate"/></property>     
    </bean> 

</beans>

我遇到错误

"Error creating bean with name 'jmsMessageSender': Injection of autowired dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jms.core.JmsTemplate com.shengwang.demo.JmsMessageSender.jmsTemplate; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'connectionFactory' defined in class path resource [app-context.xml]: 
Cannot resolve reference to bean 'amqConnectionFactory' while setting constructor argument; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'amqConnectionFactory' defined in class path resource [app-context.xml]: Instantiation of bean failed; 
nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.ibm.mq.jms.MQQueueConnectionFactory]: Constructor threw exception; 
nested exception is java.lang.NoClassDefFoundError: com/ibm/disthub2/impl/client/SessionConfig

和另一个错误SAXException.

我无法连接到Websphere MQ.请提示代码中哪里有错误.

I am unable to connect to Websphere MQ. Kindly suggest where is a mistake in the code.

推荐答案

我要说的是,您需要检查代码正在运行的盒子上是否正确安装了MQ Client.仅复制WMQ jars并期望它能正常工作是一个常见的错误.您的代码将生成,但是您将从MQ类中获得此类NoClassDefFound.尽管您可能最终可以使用它来追踪可正常运行的IBM安装中的每个jar,但它不受支持(请参阅

I'd say you need to check whether MQ Client is correctly installed on the box your code is running. It is a common mistake to just copy WMQ jars and expect it to work. Your code will build, but you will get precisely this kind of NoClassDefFound from within MQ classes. While you may get it to work eventually chasing every single jar inside a working IBM installation, it will not be supported (see http://www-01.ibm.com/support/docview.wss?uid=swg21376217)

获取WMQ安装介质并在您使用的计算机上运行install.然后遍历IBM的入门"以确保其正常运行.

Obtain WMQ installation media and run install on the machine you use. Then run through IBM's "Getting Started" to make sure it's operational.

这篇关于连接到Websphere Mq的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆