1 Reply Latest reply on Aug 30, 2002 7:27 AM by adrian.brock

    JNDI Lookup problem with Servlet

    muradhak

      Hi JBosses,
      I am using Jboss3.0(jetty disbled) with tomcat4.0.3. I am having a servlet which deployed as war file in tomcat. The functionality is lookup an EJB deployed in JBoss.

      The servelt is giving error as follwing:
      exception
      ---------
      javax.servlet.ServletException: Failed to lookup from Bean

      root cause
      ----------
      javax.naming.NameNotFoundException: Name interest is not bound in this Context

      Can anyone give me a step by step procedure how to solve this.

      ejb-jar.xml
      -----------

      <ejb-name>Interest</ejb-name>
      org.jboss.docs.interest.InterestHome
      org.jboss.docs.interest.Interest
      <ejb-class>org.jboss.docs.interest.InterestBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>


      jboss.xml
      ---------

      <ejb-name>Interest</ejb-name>
      <jndi-name>interest/Interest</jndi-name>


      servlet.java
      ------------
      InitialContext jndiContext = new InitialContext();
      Object ref = jndiContext.lookup("java:comp/env/interest/Interest");

      These are extracts of the files.

      HELP!!!

        • 1. Re: JNDI Lookup problem with Servlet

          In your web.xml add

          <ejb-ref>
          <ejb-ref-name>interest/Interest</ejb-ref-name>
          <ejb-ref-type>Session</ejb-ref-type>
          org.jboss.docs.interest.Interest
          org.jboss.docs.interest.InterestBean
          </ejb-ref>

          Then make a jboss-web.xml with the following content:

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE jboss-web
          PUBLIC "-//JBoss//DTD Web Application 2.3//EN"
          "http://www.jboss.org/j2ee/dtds/jboss-web_3_0.dtd">
          <jboss-web>
          <ejb-ref>
          <ejb-ref-name>interest/Interest</ejb-ref-name>
          <jndi-name>interest/Interest</jndi-name>
          </ejb-ref>
          </jboss-web>

          You have now configured java:comp/env for the war

          If you used an ear, you would just need the following
          in your web.xml (link to the ejb-name)
          <ejb-ref>
          <ejb-ref-name>interest/Interest</ejb-ref-name>
          <ejb-ref-type>Session</ejb-ref-type>
          org.jboss.docs.interest.Interest
          org.jboss.docs.interest.InterestBean
          <ejb-link>Interest</ejb-link>
          </ejb-ref>

          Regards,
          Adrian