1 Reply Latest reply on Jun 16, 2006 9:34 AM by hallorant

    Simple example registering an EJB 3.0 bean into a WAR's ENC

    hallorant

      I've searched and searched and could not find out how to register an EJB 3.0 bean into a WAR's ENC.

      If I have a session bean:


      @Stateless
      public class LogicBean implements Logic { ... }



      Where the interface Logic is the remote and local interface. This is deployed into a Jar. And works fine in Jboss (via Java application clients). But I can't get it to talk to a WAR when it is deployed in an EAR.

      Now I have a servlet

      public class ExampleServlet extends HttpServlet {
      
       Logic agent;
      
       @Override
       public void init() throws ServletException {
       try {
       Context context = new InitialContext();
       Object ref = context.lookup("java:comp/ejb/LogicBean/remote");
       agent = (Logic) PortableRemoteObject.narrow(ref, Logic.class);
       } catch (Exception e) {
       throw new ServletException(e.getMessage(), e);
       }
       }
       ...
      }


        • 1. Re: Simple example registering an EJB 3.0 bean into a WAR's
          hallorant

          OK, hit post rather than preview...sorry

          one line in the code is a typo, it should be:

          Object ref = context.lookup("java:comp/env/ejb/LogicBean/remote");


          My question is how to configure the web.xml and jboss-web.xml so that the servlet knows about my EJB? Can someone post or point me toward an example, using a EJB 3.0 bean, that explains how to configure the <ejb-ref> tag in both web files. Thanks in advance, I'v been playing with this for a few days and had no luck.

          A second question relates to the first. What, besides the remote/local interface, classes related to the EJB need to be in the WAR for things to work? In the old days the container produced a client JAR, what does one do in EJB 3.0 in JBoss? Thanks!!