Spring jms failing to connect to Websphere MQ - Resource Exception
Asked Answered
B

2

0

Issue: Getting resource exception at runtime attempting to connect to a websphere mq to get a jms message using spring. I just can't determine what I am missing?

Description: Attempting to set up the example here. Spring MDP Activation Spec for Websphere MQ.

https://mcmap.net/q/1641178/-spring-jms-and-websphere-mq

Maven Dependencies Note: Version numbers for the ibm jars looks odd because I created a local repo in my project to add the 3rd party libraries. I'm taking the ibm jars from my local Websphere SDP version for Websphere 7.5 . I also tried directly adding the jar dependencies on the STS spring package and had the same error.

Maven Dependencies

Spring Config 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:int="http://www.springframework.org/schema/integration"
    xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
    xmlns:jms="http://www.springframework.org/schema/jms"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.1.xsd
        http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-4.1.xsd
        http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.1.xsd">


     <bean id="messageListener" class="myproject.spring.integration.mq.SpringMdp" />  

     <bean id="messageListener" class="com.rohid.samples.SpringMdp" />  

     <bean class="org.springframework.jms.listener.endpoint.JmsMessageEndpointManager">
         <property name="activationSpec">
           <bean class="com.ibm.mq.connector.inbound.ActivationSpecImpl">
               <property name="destinationType" value="javax.jms.Queue"/>
               <property name="destination" value="QUEUE1"/>
               <property name="hostName" value="A.B.C"/>
                   <property name="queueManager" value="QM_"/>
               <property name="port" value="1414"/>
               <property name="channel" value="SYSTEM.ADMIN.SVNNN"/>
               <property name="transportType" value="CLIENT"/>
               <property name="userName" value="abc"/>
               <property name="password" value="jabc"/>
            </bean>
          </property>
          <property name="messageListener" ref="messageListener"/>
          <property name="resourceAdapter" ref="myResourceAdapterBean"/>
    </bean>

    <bean id="myResourceAdapterBean" org.springframework.jca.support.ResourceAdapterFactoryBean">
      <property name="resourceAdapter">
        <bean class="com.ibm.mq.connector.ResourceAdapterImpl">
          <property name="maxConnections" value="50"/>
        </bean>
      </property>
      <property name="workManager">
         <bean class="org.springframework.jca.work.SimpleTaskWorkManager"/>
      </property>
     </bean>
</beans>

Stack Trace:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jms.listener.endpoint.JmsMessageEndpointManager#0' defined in class path resource [context.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/resource/ResourceException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1101)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at myproject.spring.integration.mq.Main.main(Main.java:9)
Caused by: java.lang.NoClassDefFoundError: javax/resource/ResourceException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.getDeclaredConstructor(Unknown Source)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1094)
    ... 13 more
Caused by: java.lang.ClassNotFoundException: javax.resource.ResourceException
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 19 more

Updated- Solution: Required IBM Jar dependencies required. enter image description here

Blinders answered 27/8, 2015 at 19:12 Comment(0)
P
0

Looks like you are missing some dependencies here. Can you try to add javaee-api to your pom file?

<dependency>
   <groupId>javax</groupId>
   <artifactId>javaee-api</artifactId>
   <version>6.0</version> <!-- or take version 7.0 if needed -->
</dependency>
Pettus answered 28/8, 2015 at 7:54 Comment(3)
Thanks for the note. I tried this and got a different error, but the error I got mentions you need to download the full javaee jar. I'm going to try the one packaged in websphere. Error creating bean with name 'org.springframework.jms.listener.endpoint.JmsMessageEndpointManager#0' defined in class path resource [context.xml]: Instantiation of bean failed; nested exception is java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/resource/ResourceExceptionBlinders
I also just tried using the JAVA EE7 SDK javaee jar from glashfish. Still getting a resource exception.Blinders
The key jar that was missing i took from the IBM WebSphere library is the j2ee.jar . I was missing a couple other ibm ones for mq but once I had that j2ee.jar I could trace the others. Trying to find an alternative to the j2ee.jar that would work with STS.Blinders
Z
0

Generally the easiest way to get the classpath right in RAD or other IBM tools for applications that are ultimately going to be deployed to WAS is to load the server runtime library of the WAS version into your app.

It is very easy. Go to the app properties page, go to build path, libraries tab and click add Library. You will see the screen shot below. Choose server runtimes and as long as you have installed the correct WAS versions as part of RAD, you will see their runtimes.

This is generally the best way to go since it allows you to keep you WAS libraries separate from your app, but to still make them available for compilation. The worst thing you can do is embed WAS libraries as part of your app. If you do this and you deploy your app to different versions of WAS, then you will get weird classpath or weird runtime errors. On top of that, things that were working might stop working after fixpacks get applied or other software adjustments.

This is the server runtime screen you will need to choose.

If you add the server runtime library, then this is what your app will look like in RAD. This is the result of adding a server runtime to your app.

Zingg answered 30/10, 2015 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.