在Java REST服务中浏览IBM MQ时的ResourceException

时间:2018-05-25 15:58:09

标签: java spring tomcat jms ibm-mq

我编写的代码连接到IBM MQ并浏览队列。 该程序在独立运行时运行正常,但在基于Spring的Rest API(使用tomcat)中运行时,它会因ResourceException而失败

我正在使用以下库:

java.lang.NoClassDefFoundError: javax/resource/ResourceException
    at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:203)
    at com.ibm.msg.client.wmq.internal.WMQMessageConsumer.checkJmqiCallSuccess(WMQMessageConsumer.java:222)
    at com.ibm.msg.client.wmq.internal.WMQMessageConsumer.checkJmqiCallSuccess(WMQMessageConsumer.java:156)
    at com.ibm.msg.client.wmq.internal.WMQConsumerShadow.getMsg(WMQConsumerShadow.java:1861)
    at com.ibm.msg.client.wmq.internal.WMQSyncConsumerShadow.receiveInternal(WMQSyncConsumerShadow.java:230)
    at com.ibm.msg.client.wmq.internal.WMQConsumerShadow.receive(WMQConsumerShadow.java:1466)
    at com.ibm.msg.client.wmq.internal.WMQQueueEnumeration.retrieveMessage(WMQQueueEnumeration.java:370)
    at com.ibm.msg.client.wmq.internal.WMQQueueEnumeration.hasMoreElements(WMQQueueEnumeration.java:291)
    at com.ibm.msg.client.jms.internal.JmsQueueBrowserImpl$JmsEnumImpl.hasMoreElements(JmsQueueBrowserImpl.java:362)
    at com.ibm.mq.jms.MQQueueEnumeration.hasMoreElements(MQQueueEnumeration.java:91)
    at xxxxxxxxxxxxxxxxxxxx.TestMessage.messageExists(TestMessage.java:89)
    at xxxxxxxxxxxxxxxxxxxx.TestMessage.main(TestMessage.java:28)
Caused by: java.lang.ClassNotFoundException: javax.resource.ResourceException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 12 more

该计划:如下:

compile('org.springframework.boot:spring-boot-starter-web') 
compile('org.springframework.boot:spring-boot-starter-aop') 
compile('org.springframework:spring-aspects') 
compile("org.springframework.boot:spring-boot-starter-data-mongodb")

compile group: 'commons-io', name: 'commons-io', version: '2.5'
compile group: 'org.apache.commons', name: 'commons-vfs2', version: '2.1'
compile group: 'de.odysseus.staxon', name: 'staxon', version: '1.3'
compile group: 'net.sourceforge.jtds', name: 'jtds', version: '1.3.1'

compile fileTree(dir: "lib", includes: ['*.jar'])

compile('org.springframework.boot:spring-boot-starter-test') 
compile group: 'commons-dbcp', name: 'commons-dbcp', version: '1.4'
compile 'org.hibernate:hibernate-core:5.2.4.Final'

compile (group: 'jcifs', name: 'jcifs', version: '1.3.17'){
    exclude group: 'javax.servlet', module: 'servlet-api'
}   
compile group: 'net.sf.ehcache', name: 'ehcache', version: '2.10.2.2.21'
compile group: 'org.apache.commons', name: 'commons-pool2', version: '2.4.2'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.4'
compile 'org.hibernate:hibernate-core:5.2.4.Final'    
compile group: 'org.hibernate', name: 'hibernate-c3p0', version: '5.2.4.Final'
compile group: 'com.thoughtworks.xstream', name: 'xstream', version: '1.4.10'

testCompile group: 'com.mockrunner', name: 'mockrunner-jdbc', version: '1.1.2'
testCompile("junit:junit")
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '1.6.4'
testCompile group: 'org.powermock', name: 'powermock-api-mockito', version: '1.6.4'

错误跟踪是:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add("username", null, array(
        "label" => "Email",
        "attr" => array(
            "class" => "form-control",
            "id" => "basic-url",
            "placeholder" => "Email address for your account"
        ),
        "constraints" => array(
            new Email(array("message" => "Invalid Email"))
        )
    ));
}

有人可以帮助我找到问题。 我正在使用Spring 4,Gradle,tomcat,Spring boot

以下是gradle依赖项:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    parent::buildForm($builder, $options);
    $builder
        ->add('plainPassword', RepeatedType::class, array(
            'type'              => PasswordType::class,
            'required'          => false,
            'first_options'     => array('label' => 'New password'),
            'second_options'    => array('label' => 'Confirm new password'),
            'invalid_message' => 'The password fields must match.',
        ))
        ;
}

1 个答案:

答案 0 :(得分:0)

我通过添加以下内容解决了该问题。基本上,异常是由于与ibm mq相关的jar发生冲突而来的。在下面添加即可解决问题。

    compile("com.ibm.mq:mq-jms-spring-boot-starter:+")