Announcement Announcement Module
Collapse
No announcement yet.
JNDI lookup for an EJB with WAS 5.1 fails Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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>

    Comment


    • #3
      Also had to set lazy-init=&quot;true&quot;

      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>

      Comment

      Working...
      X