2 Replies Latest reply on Jun 10, 2006 11:43 PM by Ranjit Notani

    EJB3 Stateless Session Bean not bound error

    Ranjit Notani Newbie

      Hi,

      I have a really simple EJB3 sample adapted from the Trailblazer application.
      I have a Servlet (ExampleServlet.java) that does a lookup of a Stateless Session Bean (TestServiceImpl.java).

      The lookup code is


      Context jndiContext = new jndiContext();
      TestService ts = (TestService)jndiContext.lookup("TestServiceImpl");


      When I do this I get a javax.naming.NameNotFoundException: TestServiceImpl not found.

      When I print out the JNDI context from the Servlet, I do not see TestServiceImpl or anything related to my beans.

      My application is packaged as a single ear file (example.ear) which contains


      application.xml
      jboss-app.xml
      app.jar
      ....TestService.java
      .....TestServiceImpl.java
      .....Persistence.xml
      web.war
      .....ExampleServlet.class
      ......MyJSP.jsp
      ......web.xml


      My TestServiceImpl class looks like


      @Stateless
      @Local(TestService.class)
      @LocalBinding(jndiBinding="TestServiceImpl")
      public class TestServiceImpl implements TestService
      public int add(int i, int j)
      { return i+j;
      }
      }


      The @Local and at @LocalBinding are recent additions. Initially I
      did not have them and tried the following context lookups to
      no avail.


      TestService ts = (TestService)jndiContext.lookup("example/TestServiceImpl/local");

      Note: my ear file is example.ear

      TestService ts = (TestService)jndiContext.lookup("TestServiceImpl/local");



      When I deploy the ear file (example.ear) into JBoss (I am using JBoss 4.0.4) I get no errors and the Servlet and JSP invoke fine.


      My persistence.xml file is:


      <persistence>
      ....<persistence-unit name="example">
      ..........<jta-data-source>java:/DefaultDS</jta-data-source>
      ......</persistence-unit>
      </persistence>


      My application.xml file is: (ignore the dots in "module" and "web" below...
      I needed those to prevent this forum software from getting confused)

      .... usual XML headers ....
      <display-name>Example Application</display-name>
      <module.>
      .....<ejb>app.jar</ejb>
      </module.>
      <module.>
      ......<web.>
      .............<web-uri>web.war</web-uri>
      ..............<context-root>Example</context-root>
      ......</web.>
      </module.>



      My jboss-app.xml file is

      ... usual XML headers...
      <jboss-app>
      ....<loader-repository>
      ...........example:app=ejb3
      .....</loader-repository>
      </jboss-app>


      My jboss-web.xml file is

      .... usual XML headers
      <jboss-web>
      ....<security-domain>java:/jaas/other</security-domain>
      </jboss-web>


      My web.xml file is

      .... usual XML headers
      <web-app>
      ......<display-name>Example</display-name>
      ......<servlet>
      ............<servlet-name>ExampleServlet</servlet-name>
      ...........<servlet-class>web.other_servlets.ExampleServlet</servlet-name>
      ......</servlet>


      .......<servlet-mapping>
      ............<servlet-name>ExampleServlet</servlet-name>
      ............<url-pattern>/do/*</url-pattern>
      .......<servlet-mapping>

      </web-app>



      I have been struggling over this for the past 2 days, so any help will be greatly appreciated..

      My current hypotheses are
      1) Some configuration error that I cannot pick up
      2) The stateless session bean (ExampleServiceImpl) is being
      registered in some naming context the the Servlet does not
      have access to.
      3) The stateless session bean is not getting registered at all (despite
      no errors on deploy).

      thanks,

      Ranjit



        • 1. Re: EJB3 Stateless Session Bean not bound error
          Ranjit Notani Newbie

          Ok, I don't feel so bad now...

          When I deploy EJB3Trail.ear I get the same problem.

          When I click on the "Try the calculator" button
          in the Stateless Session Bean section I get the same
          problem.

          I get a javax.naming.NameNotFoundException: EJB3Trail not
          bound.

          I am running JBoss 4.0.4.GA. From what I understand this
          version of JBoss has EJB3 built in.. Am I right? Or do I need
          to use another version of JBoss and/or do some further installation
          to add EJB3.

          thanks,

          Ranjit

          • 2. Re: EJB3 Stateless Session Bean not bound error
            Ranjit Notani Newbie


            Well, looks like I found out the problem.

            To get JBoss 4.0.4, you have 2 options, viz. "Download" or
            "Installer".

            Earlier I had used "Download" and simply unzipped 4.0.4 into
            a directory. Apparently that installs a version of JBoss WITHOUT
            ejb3.

            However, if you go the "Installer" route, you will get a chance to
            pick an "ejb3" option.

            Hope this helps other people avoid the same mistake.

            Ranjit