Announcement Announcement Module
Collapse
No announcement yet.
Websphere MQ 6.0 + Websphere 5.1 + Spring - JNDI NameNotFoundException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Websphere MQ 6.0 + Websphere 5.1 + Spring - JNDI NameNotFoundException

    Hello

    I am trying to send a message to a local websphere mq server using spring and I am getting the following error message. My config file is also given below. I tested the QueueConnectionFactory and Queue by using a regular jndi context lookup and it works fine. What am I doing wrong here?? Please help.

    HTML Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsTemplate' defined in class path resource[beans/batchContext.xml]: Cannot resolve reference to bean 'jmsQueueConnectionFactory' while setting bean property 'connectionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsQueueConnectionFactory' defined in class path resource [beans/batchContext.xml]: Cannot resolve reference to bean 'jmsInternalQueueConnectionFactory' while setting bean property 'targetConnectionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsInternalQueueConnectionFactory' defined in class path resource [beans/batchContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jms/batchQCF

    Code:
    <beans>
    	
    	<!-- JMS Sender -->
    	<bean id="jmsSender" class="com.test.BatchServiceMessageSender">
    		<property name= "jmsTemplate">
    			<ref bean="jmsTemplate"/>
    		</property>	
    	</bean>	
    
    
    	<!--  JMS Template Definitions -->
    	<bean id="jmsInternalQueueConnectionFactory"
    		class="org.springframework.jndi.JndiObjectFactoryBean">
    	    <property name="jndiTemplate">
    	        <ref bean="jndiTemplate"/>
    	    </property>
    	    <property name="jndiName">
    	        <value>jms/batchQCF</value>
    	    </property>
    	</bean>
    
    
    <!-- Spring JMS Queue Connection Factory -->
    	<bean id="jmsQueueConnectionFactory"
    	class="org.springframework.jms.connection.SingleConnectionFactory">
    	<property name="targetConnectionFactory">
    		<ref bean="jmsInternalQueueConnectionFactory"/>
    	</property>
    	</bean>
    
        <bean id="destination"
    	    class="org.springframework.jndi.JndiObjectFactoryBean">
    	    <property name="jndiTemplate">
    	        <ref bean="jndiTemplate"/>
    	    </property>
    	    <property name="jndiName">
    	        <value>jms/batchQ</value>
    	    </property>
    	</bean>
    	
    	<bean id="jmsTemplate" 
    	    class="org.springframework.jms.core.JmsTemplate102">
    	    <property name="connectionFactory">
    	        <ref bean="jmsQueueConnectionFactory"/>
    	    </property>
    	    <property name="defaultDestination">
    	        <ref bean="destination"/>
    	    </property>
    	    <property name="receiveTimeout">
    	        <value>30000</value>
    	    </property>
    	</bean>
    	  
    	<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
        <property name="environment">
          <props>
            <prop key="java.naming.factory.initial">
                com.sun.jndi.fscontext.RefFSContextFactory
            </prop>
            <prop key="java.naming.provider.url">
                file:/C:/JNDI-Directory
            </prop>
          </props>
        </property>
      </bean>
    
    	<bean id="BatchService" class="com.test.BatchService">
    		<property name="batchServiceUtil"> 
    			<ref bean="jmsSender"/>
    		</property>
    
    	</bean>
    
    <!-- Message Listener POJO-->
    	<bean id="messageListener" class="com.test.BatchServiceMessageListener"/>
    
    	<bean id="listenerContainer" 
    		class="org.springframework.jms.listener.DefaultMessageListenerContainer102">
    	 <property name="concurrentConsumers" value="5"/>
    	 <property name="connectionFactory" ref="jmsQueueConnectionFactory"/>
    	 <property name="destination" ref="destination"/>
     	 <property name="messageListener" ref="messageListener"/>
    
     	 </bean>
    </beans>

  • #2
    This exception is essentially just a wrapped JNDI lookup failure: there is no object bound at the JNDI location "jms/batchQCF". Please double-check where the object is actually bound; is there maybe a prefix missing? What exactly did you specify in your programmatic test code when you performed the JNDI lookup - does this actually match your JNDI configuration here?

    Juergen

    Comment


    • #3
      Thank you for replying. This is the test code which wrote the message to mq.

      Code:
      InitialContext context = new InitialContext();
      QueueConnectionFactory  cf = (QueueConnectionFactory)context.lookup("jms/batchQCF");
      QueueConnection  conn = cf.createQueueConnection();
      conn.start();
      QueueSession jmsSession = conn.createQueueSession(false,Session.AUTO_ACKNOWLEDGE); 
      Queue queue =(Queue)context.lookup("jms/batchQ");
      QueueSender queueSender = jmsSession.createSender(queue); 
      TextMessage message = jmsSession.createTextMessage();
      message.setText("Test String");
      queueSender.send(message); 
      queueSender.close();
      jmsSession.close();
      I also tried adding the prefix "java:comp/env/" but it didnt work.

      Comment


      • #4
        Any ideas why I am seeing this error ?

        Comment


        • #5
          Hi,

          i would recommend to dump your JNDI Namespace on the server and double check if the JNDI Name is avaiable. (Like mentioned before)
          If you are using RAD you can do this via the Universal Test Client, there you should see your JNDI definitions.

          regards
          lyserg

          Comment


          • #6
            I used the dumpNamespace tool and it shows me the JNDI properties for the queue and queue connection factory as follows.

            JTS.TransactionFactoryImpl
            28 (top)/nodes/localhost/servers/server1/jms javax.naming.Context
            29 (top)/nodes/localhost/servers/server1/jms/batchQCF javax.jms.QueueConnectionFactory
            30 (top)/nodes/localhost/servers/server1/jms/batchQ com.ibm.mq.jms.MQQueue

            Comment


            • #7
              Hi,

              i am confused,
              in the propertys you are using the SUNFSJNDIContext as the JNDI Provider to look up your beans.
              Code:
               <prop key="java.naming.factory.initial">
                          com.sun.jndi.fscontext.RefFSContextFactory
                      </prop>
                      <prop key="java.naming.provider.url">
                          file:/C:/JNDI-Directory
                      </prop>
              And you JNDI Namespace Dump looks like a websphere dump.

              Regards
              lyserg

              Comment


              • #8
                Thank you for replying. I did the configuation according to this web article.

                http://www-128.ibm.com/developerwork...ry/wa-spring4/

                Comment


                • #9
                  You probably don't need to define the jndiTemplate bean if you are running this configuration on the Websphere server. You can remove the definition and in the jmsTemplate bean, simply set the defaultDestinationName to the desired JNDI location.

                  Comment


                  • #10
                    Hi Thathu,
                    I am extremly new to Spring and have to work on JMS. I am actually in the same boat as you are.
                    Are you able to work through this example?
                    What modifications did you do?
                    I am not sure how to setup ConnectionFactory?

                    Thanks for your help.

                    Comment


                    • #11
                      RazorMirage,

                      See my post above. Remove the jndiTemplate and simply let the Websphere container handle the InitialContext type to use and the provider URL internally.

                      Comment


                      • #12
                        Originally posted by fiddlerpianist View Post
                        RazorMirage,

                        See my post above. Remove the jndiTemplate and simply let the Websphere container handle the InitialContext type to use and the provider URL internally.
                        fiddlerpianist,
                        My Spring classes are
                        -Creating JMs message
                        -Sending to Websphere MQ
                        When I am sending to Websphere MQ then also I shd drop jndiTemplate?

                        Comment


                        • #13
                          Originally posted by razorMirage View Post
                          fiddlerpianist,
                          My Spring classes are
                          -Creating JMs message
                          -Sending to Websphere MQ
                          When I am sending to Websphere MQ then also I shd drop jndiTemplate?
                          The jndiTemplate you are using is for a sample. You should be using the InitialContext that is provided by Websphere, i.e. new InitialContext() (the default) should be returning the correct context. That's how Spring does things under the covers if you do not configure a JndiTemplate.

                          Comment


                          • #14
                            fiddlerP..
                            "...InitialContext that is provided by Websphere..."??
                            Where is this Websphere is coming? I am saying this "Sending Queue Code" is NOT sitting in any AS.
                            I am talking here of sending messages to Websphere MQ ans not Websphere AS.
                            The whole story of my problem is
                            "There is some stand-alone code sending messages to MQ. How?".

                            Comment


                            • #15
                              Originally posted by razorMirage View Post
                              fiddlerP..
                              "...InitialContext that is provided by Websphere..."??
                              Where is this Websphere is coming? I am saying this "Sending Queue Code" is NOT sitting in any AS.
                              I am talking here of sending messages to Websphere MQ ans not Websphere AS.
                              The whole story of my problem is
                              "There is some stand-alone code sending messages to MQ. How?".
                              You indicated that you were having the same problems as the other fellow, who was running Websphere Application Server. So I assumed that you, too, were running Websphere Application Server.

                              If you need to specify parameters to the InitialContext (i.e. in your code "new InitialContext()" doesn't work correctly), then you should use the JndiTemplate, but you have to customize it to the JNDI environment that your code is using. You can't just take the example verbatim from the article and expect it to work. Your parameters have to match the JNDI implementation you are using.

                              If you aren't using JNDI to obtain a QueueConnectionFactory (i.e. you have one running in memory, something such as an in-memory ActiveMQ QCF) you can directly inject the QueueConnectionFactory as a property to the JmsTemplate on startup.

                              Comment

                              Working...
                              X