gpt4 book ai didi

spring - 如何从 Spring 中对 Websphere 应用服务器中定义的 MQ 连接工厂进行 jndi 查找

转载 作者:行者123 更新时间:2023-12-04 20:12:32 25 4
gpt4 key购买 nike

我正在尝试连接到 Websphere app Server 7.0 中定义的 MQ 连接工厂。

但是我找不到在 Spring 中定义 MQ 的正确 connectionfactory 接口(interface)。

但是,当我尝试在 spring 配置文件中硬编码连接详细信息时,我能够连接到队列管理器。

在 Spring bean 中使用什么正确的接口(interface)/格式来加载 Websphere appl 服务器中定义的 MQ 连接工厂?

工作代码

<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>

不工作代码
<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>

其中 WASQM 是 Websphere 中定义的 MQ 连接工厂

错误代码
 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

我需要帮助来用正确的代码替换不工作的代码。
Spring - 3.0.5
IBM MQ 和 Web 应用服务器 - 7.0

最佳答案

正确的做法是

  • 在 Websphere App Server 的队列连接工厂中创建资源(不在连接工厂中)
  • 在 spring config 中使用 javax.jms.QueueConnectionFactory 作为连接工厂
    <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>

  • 这个 page给了我提示。

    关于spring - 如何从 Spring 中对 Websphere 应用服务器中定义的 MQ 连接工厂进行 jndi 查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15546685/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com