How to do jndi lookup of MQ connection factory defined in Websphere app Server from Spring

纵然是瞬间 提交于 2019-12-07 04:45:17

问题


I am trying to connect to a MQ connection factory defined in Websphere app Server 7.0.

But I couldnt find a right connectionfactory interface for the MQ to define in Spring.

However when I tried to hardcode the connection details in the spring config file, I am able to connect to the Queue Manager.

What is the right interface/format to use in Spring beans to load the MQ connection factory defined in Websphere appl server?

Working Code

<bean id="mqConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
    <property name="hostName">
        <value>127.0.0.1</value>
    </property>
    <property name="port">
        <value>1414</value>
    </property>
    <property name="queueManager">
        <value>MYQM</value>
    </property>
    <property name="transportType">
        <value>1</value>
    </property>
</bean>

Not Working Code

<bean id="mqConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jms/WASQM"/>
    <property name="lookupOnStartup" value="false"/>
    <property name="cache" value="true" />
    <property name="proxyInterface"  value="com.ibm.mq.jms.MQQueueConnectionFactoryFactory" />
</bean>

where WASQM is the MQ connection factory defined in Websphere

Error with the Non working code

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mqConnectionFactory' defined in ServletContext resource [/WEB-INF/config/config-mq.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: [com.ibm.mq.jms.MQQueueConnectionFactoryFactory] is not an interface
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
Caused by: java.lang.IllegalArgumentException: [com.ibm.mq.jms.MQQueueConnectionFactoryFactory] is not an interface

I need help in replacing the not working code with a right code. Spring - 3.0.5 IBM MQ and Web App Servers - 7.0


回答1:


Right way to do is

  1. Create the resource in Queue Connection Factory in Websphere App Server (not in Connection Factory)
  2. Use javax.jms.QueueConnectionFactory as the connection factory in spring config

    <bean id="mqConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
       <property name="jndiName" value="WASQM"/>
       <property name="lookupOnStartup" value="false"/>
       <property name="cache" value="true" />
       <property name="proxyInterface"  value="javax.jms.QueueConnectionFactory" />
    </bean>
    

This page gave me the hint.



来源:https://stackoverflow.com/questions/15546685/how-to-do-jndi-lookup-of-mq-connection-factory-defined-in-websphere-app-server-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!