4 Replies Latest reply on Sep 4, 2003 9:58 AM by dsvmd

    Problem referencing an EJB from Web app

    dsvmd

      Hello,

      As a new user to JBoss, I created HelloWorld example and tried to test it via Cactus. When I deployed it, the HelloWorld EJB deployed fine but the web application failed with the following error:

      org.jboss.deployment.DeploymentException: Error during deploy; - nested throwable: (javax.naming.NamingException: ejb-ref: ejb/HelloWorld, no ejb-link in web.xml and no jndi-name in jboss-web.xml)

      Here are my deployment descriptors:

      ejb-jar.xml

      <ejb-jar >
      <enterprise-beans>

      Simple HelloWorld statless session EJB.>
      <ejb-name>HelloWorld</ejb-name>
      bfd.tests.hello_world.HelloWorldHome
      bfd.tests.hello_world.HelloWorld
      <local-home>bfd.tests.hello_world.HelloWorldLocalHome</local-home>
      bfd.tests.hello_world.HelloWorldLocal
      <ejb-class>bfd.tests.hello_world.HelloWorldBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>

      </enterprise-beans>
      <assembly-descriptor >
      </assembly-descriptor>
      </ejb-jar>

      jboss.xml


      <enterprise-beans>

      <ejb-name>HelloWorld</ejb-name>
      <jndi-name>ejb/HelloWorld</jndi-name>
      <local-jndi-name>ejb/HelloWorldLocal</local-jndi-name>

      </enterprise-beans>
      <resource-managers>
      </resource-managers>


      web.xml

      <web-app>

      <servlet-name>ServletRedirector</servlet-name>
      <servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class>

      <servlet-mapping>
      <servlet-name>ServletRedirector</servlet-name>
      <url-pattern>/ServletRedirector</url-pattern>
      </servlet-mapping>
      <ejb-ref>
      <ejb-ref-name>ejb/HelloWorld</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      bfd.tests.hello_world.HelloWorldHome
      bfd.tests.hello_world.HelloWorld
      <ejb-link>ejb/HelloWorld</ejb-link>
      </ejb-ref>
      </web-app>

      After a little playing around I got it to deploy and work correctly by altering the web.xml file. I replaced

      <ejb-ref-name>ejb/HelloWorld</ejb-ref-name>
      <ejb-link>ejb/HelloWorld</ejb-link>

      with

      <ejb-ref-name>HelloWorld</ejb-ref-name>
      <ejb-link>HelloWorld</ejb-link>

      Can anyone tell what's going on here? Why did this work? In addition, why do you need the <ejb-link> tag.

      Thanks,

      Dan

        • 1. Re: Problem referencing an EJB from Web app
          raja05

          the ejb-link value should match the <ejb-name> in your ejb-jar.xml. This is a convenient way to reference the EJBs without referencing the actual JNDI name in jboss-web.xml. In your initial code, you had a ejb-link value of ejb/HelloWorld and there was no entry in your ejb-jar.xml with that ejb-name.

          When you changed it to HelloWorld, your ejb-name in ejb-jar.xml was equal to the ejb-link tag in web.xml and so it deployed fine.
          If you wanted your original code to work, rename the ejb-name in ejb-jar.xml to be ejb/HelloWorld

          HTH
          Raj

          • 2. Re: Problem referencing an EJB from Web app
            dsvmd

            RAH,

            Thank you for you help. Do you think you can help explain one more scenario? This time I set the ejb-link tag to "HelloWorld" and the ejb-ref-name tag to "ejb/HelloWorld" in my web.xml file. When I tried to reference the ejb from a Servlet using "ejb/HelloWorld" I got the following exception:

            javax.naming.NameNotFoundException: HelloWorld not bound

            However, when I referenced the ejb from a Servlet using "HelloWorld" it worked fine. What is going on here? Isn't the Serlvet supposed to use the ejb-ref-name tag for references?

            • 3. Re: Problem referencing an EJB from Web app
              raja05

              ejb-ref-name is used so that you can reference ur EJBs in a deployment independent way. For e.g. i can jndi my ejb as ABC today but if i had to change it to DEF , i would have to change my code and recompile if i used ABC as the lookup in the servlet code. Instead if i use a reference like ejb/MyBean and map that to "ABC", my chnages would only be limited to the deployment descriptor. Thats the whole point in having ejb-ref-name.
              REgarding ur situation, if ur ejb-ref-name is ejb/HelloWorld, you should reference it as
              java:comp/env/ejb/HelloWorld from your servlet and it should reference fine if ur ejb-link is HelloWorld and ur ejb-name in ejb-jar.xml is HelloWorld.
              Isnt this happening in ur case?

              -Raj

              • 4. Re: Problem referencing an EJB from Web app
                dsvmd

                Raj,

                Once I put " java:comp/env/ejb/HelloWorld" into the lookup ot worked fine. Before I was just using "ejb/HelloWorld".

                Thanks,

                Dan