Results 1 to 3 of 3

Thread: JNDI lookup for an EJB with WAS 5.1 fails

  1. #1
    Join Date
    May 2005
    Posts
    3

    Default JNDI lookup for an EJB with WAS 5.1 fails

    Hello,
    We are using WAS 5.1 we get a JNDI lookup naming exception.
    NameNotFoundException :-
    [26/05/05 14:18:12:134 EST] 1654a121 DefaultListab I org.springframework.beans.factory.support.DefaultL istableBeanFactory Creating shared instance of singleton bean 'loaderQueue'

    [26/05/05 14:18:12:134 EST] 1654a121 DefaultListab I org.springframework.beans.factory.support.DefaultL istableBeanFactory Creating shared instance of singleton bean 'extractorSession'

    [26/05/05 14:18:12:197 EST] 1654a121 DefaultListab I org.springframework.beans.factory.support.DefaultL istableBeanFactory Destroying singletons in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [extractorQueueConnectionFactory,loaderQueueConnect ionFactory,extractorQueue,loaderQueue,extractorSes sion,loaderSession,messageLoaderSession,schemaInst anceLoaderSession,senderSession]; root of BeanFactory hierarchy}
    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'extractorSession' defined in class path resource [applicationContext-ejb.xml]: Initialization of bean failed; nested exception is javax.naming.NameNotFoundException: Context: mbkw055227/nodes/mbkw055227/servers/server1, name: ejb/session/OTKR/ExtractorSessionBean: First component in name ejb/session/OTKR/ExtractorSessionBean not found.


    Code:-
    Here is the reference in the applicationContext-ejb.xml file
    <bean id="loaderQueue"
    class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>jms/queue/OTKR/LoaderQueue</value>
    </property>
    </bean>
    <bean id="extractorSession"
    class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>ejb/session/ExtractorSessionBean</value>
    </property>
    </bean>

    We look this up from the ejbCreate() of our MessageDrivenBean code:-
    Here is the x-doclet references in the header of MessageDrivenBean:-
    Below are the xdoclet-related tags needed for this EJB.
    *
    * @ejb.resource-ref res-ref-name="jms/queue/OTKR/LoaderQueueConnectionFactory"
    * res-type="javax.jms.QueueConnectionFactory"
    * res-auth="Container"
    * jndi-name="java:comp/env/jms/queue/OTKR/LoaderQueueConnectionFactory"
    *
    * @ejb.ejb-ref ejb-name="LoaderSessionBean" view-type="local"
    * ref-name="ejb/session/OTKR/LoaderSessionBean"
    *
    * @ejb.bean name="LoaderMessageDrivenBean"
    * display-name="LoaderMessageDrivenBean"
    * description="This is a message-driven bean which reads messages off
    * the loader input queue and then calls the loader bean to perform
    * loading of products and sends to the extractor input queue"
    * destination-type="javax.jms.Queue"
    * transaction-type="Container"
    */

    ejbCreate method code:-
    public void ejbCreate()
    {
    logger.debug("ejbCreate [start]");
    try
    {
    logger.debug("looking up queue connection");
    InitialContext initialContext = new InitialContext();

    // define the queue connection factory
    QueueConnectionFactory qcf = (QueueConnectionFactory) ApplicationContextEJB.getInstance().getBean(Applic ationContextEJB.LOADER_QUEUE_CONNECTION_FACTORY);
    logger.debug("looking up queue connection[done]");
    connection = qcf.createQueueConnection();
    logger.debug("creating queue connection");
    session = connection.createQueueSession(true, 0);
    logger.debug("looked up queue connection");
    connection.start();

    logger.debug("queue connection [started]");

    // define the extractor session bean

    LoaderSessionBeanLocalHome loaderSessionBeanLocalHome = (LoaderSessionBeanLocalHome) ApplicationContextEJB.getInstance().getBean(Applic ationContextEJB.LOADER_SESSION);
    loaderSessionBeanLocal = loaderSessionBeanLocalHome.create();

    logger.debug("ejbCreate [end]");
    }
    catch (NamingException ne)
    {
    logger.error("jndi naming failure [" + ne.getMessage() + "]", ne);
    }
    catch (CreateException ce)
    {
    logger.error("ejb create failure [" + ce.getMessage() + "]", ce);
    }
    catch (JMSException je)
    {
    logger.error("queue connection failure [" + je.getMessage() + "]", je);
    }
    }


    Then in WAS 5.1when we install our EJB reference JNDI is
    ejb/session/OTKR/ExtractorSessionBean.

    We've tried java:comp/env/ejb/session/OTKR/ExtractorSessionBean
    and variances of this.
    Before we put Spring JNDI lookup in we used this full reference from an initialContext.lookup() and it worked.

    Any help appreciated.

  2. #2
    Join Date
    May 2005
    Posts
    3

    Default Resolved by using resourceRef set to true property

    Hi,
    We've resolved this by adding the resourceRef property and setting to true on the EJB JNDIObjectFactoryBean lookup as follows:-
    <bean id="saveSession" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>ejb/SenderSessionBean</value>
    </property>
    <property name="resourceRef">
    <value>true</value>
    </property>
    </bean>

    This ensures that the JNDI property is prepended with "java:comp/env/” .
    See blog here with similar issue.
    http://erik.jteam.nl/index.php?p=6

    This seems unusual because both the dataSource lookup and our queue connection factory lookup did not require this to be set and they do not have full java:comp/env/ references in their jndiName so you would think they would need this prepend aswell but ours works without it being set
    e.g.
    <bean id="loaderOutputQueueConnectionFactory"
    class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>jms/queue/OTKR/LoaderOutputQueueConnectionFactory</value>
    </property>
    </bean>

    DataSource:-
    bean id="kpiDataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>jdbc/jtds/KPIDataStore</value>
    </property>
    </bean>

  3. #3
    Join Date
    May 2005
    Posts
    3

    Default Also had to set lazy-init="true"

    Forgot to say, also had to set lazy-init to true in our applicationContext-ejb-jndi.xml as when first lookup is done the other beans referenced do not have their jndi name set up yet so we would get a jndi naming exception.
    <bean id="extractorSession" lazy-init="true"
    class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>ejb/session/OTKR/ExtractorSessionBean</value>
    </property>
    <property name="resourceRef">
    <value>true</value>
    </property>
    </bean>

Similar Threads

  1. Replies: 7
    Last Post: Aug 29th, 2011, 05:01 AM
  2. Replies: 4
    Last Post: Jan 17th, 2007, 01:01 AM
  3. Replies: 1
    Last Post: Aug 18th, 2006, 11:04 PM
  4. JNDI DataSource lookup outside of JBoss
    By cpmcda01 in forum Data
    Replies: 4
    Last Post: Jun 15th, 2005, 03:56 PM
  5. JNDI BeanFactory lookup
    By edalquist in forum Container
    Replies: 4
    Last Post: Dec 16th, 2004, 02:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •