3 Replies Latest reply on Nov 4, 2006 2:49 AM by jaikiran

    Packing/Descriptors for EJB 3.0 Local access

    schererj123

      I'm trying to use JBoss 4.05 with EJB 3.0

      I have a simple stateless bean that I have developed and deployed into the J2EE container. If I want this bean to only be accessed from a Local scope and I've got a servlet that needs to access it, what do my deployment descriptors need to contain?

      The way I understand it I could have a jboss.xml, web-xml, application.xml and ejb-jar.xml.

      For the purpose of this discussion let's assume the bean is HelloWorldBean and I'm trying to access it using the following code..

      .....
      InitialContext ctx = new InitialContext();
      ctx.lookup("WHAT DO I PUT HERE");
      .....

      Thanks.....

        • 1. Re: Packing/Descriptors for EJB 3.0 Local access
          jaikiran

          In your ejb-jar.xml:

          <session >
           <description>Sample session bean</description>
          
           <ejb-name>HelloWorld</ejb-name>
          
          
           <local-home>packageName.HelloWorldLocalHome</local-home>
           <local>packageName.HelloWorldLocal</local>
           <ejb-class>packageName.HelloWorldSessionBean</ejb-class>
           <session-type>Stateless</session-type>
           <transaction-type>Container</transaction-type>
          
          
          
           </session>
          


          Add the following to the web.xml:

          <ejb-local-ref>
           <ejb-ref-name>ejb/MyLocalRefHelloWorld</ejb-ref-name>
           <ejb-ref-type>Session</ejb-ref-type>
           <local-home>packageName.HelloWorldLocalHome</local-home>
           <local>packageName.HelloWorldLocal</local>
           <ejb-link>HelloWorld</ejb-link>
           </ejb-local-ref>


          The ejb-link in the web.xml should match the ejb-name in the ejb-jar.xml.

          In your code, you will lookup using the ejb-ref-name specified in the web.xml, as follows:

          Context ctx = new InitialContext();
          ctx.lookup("java:comp/env/ejb/MyLocalRefHelloWorld");






          • 2. Re: Packing/Descriptors for EJB 3.0 Local access
            jaikiran

            This approach will work, but you mention that you are using EJB3. Why dont you use dependency injection of EJBs?

            • 3. Re: Packing/Descriptors for EJB 3.0 Local access
              jaikiran

               

              Why dont you use dependency injection of EJBs?


              Hmmm... Searching the forums led me to this thread which mentions that as of now dependency injection of EJB in servlets in not possible:

              http://www.jboss.com/index.html?module=bb&op=viewtopic&t=93140