jms连接工厂javax.naming.NamingException:无法创建资源工厂实例

时间:2018-02-23 11:57:06

标签: spring tomcat ibm-mq jndi

您好我正在尝试从Tomcat 8连接WebSphere IBM MQ 7.5.0.7连接工厂。启动tomcat服务器时,我们加载spring XML,从中我们连接到IBM MQ Connection工厂。

下面是spring xml中的代码。

<bean name="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="java:comp/env/JMS/QFX_PF1UATMQCF" />
        </bean>

Tomcat中Context.xml中的代码。

<Resource name="JMS/QFX_PF1UATMQCF"
        auth="Container"
        type="com.ibm.mq.jms.MQQueueConnectionFactory"
        factory="com.ibm.mq.jms.MQQueueConnectionFactoryFactory"
        description="JMS Queue Connection Factory for sending messages"
        HOST="some hostname"
        PORT="1425"
        CHAN="SYSTEM.DEF.SVRCONN"
        TRAN="1"
        QMGR="EUQFXP7A"/>   

以下是我在启动tomcat时遇到的异常。

 Cannot resolve reference to bean 'jmsConnectionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsConnectionFactory' defined in class path resource : Invocation of init method failed; nested exception is javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.NoClassDefFoundError: javax/jms/JMSException]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

1 个答案:

答案 0 :(得分:1)

您需要将至少以下JAR文件复制到Tomcat(例如$CATALINA_BASE/lib):

正如@JoshMc所提到的,你不应该再使用MQ 7.5了。

启动Tomcat时,您可能会在WARNING中看到catalina.log这样的消息:

24-Feb-2018 22:06:40.473 WARNING [localhost-startStop-1] org.apache.tomcat.util.scan.StandardJarScanner.processURLs Failed to scan [file:.../lib/jms.jar] from classloader hierarchy
 java.io.FileNotFoundException: .../lib/jms.jar (The system cannot find the file specified)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:219)

您可以通过在tomcat.util.scan.StandardJarScanFilter.jarsToSkip中将MQ jar添加到catalina.properties属性来消除这些警告。