3 Replies Latest reply on Nov 10, 2007 6:46 PM by Radu Cirstoiu

    EJB3 <ejb-local-ref> not working

    Radu Cirstoiu Newbie

      Hi
      I'm trying to use a local interface of an ejb3 in a Servlet and annotatig with @EJB won't work (jboss-4.2.2.GA) so I'm trying to inject the bean in java:comp/env/ via web.xml.
      But wen I try to use <ejb-local-ref> :

      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>Web Interface</display-name>

      .............................................

      <ejb-local-ref>
      <ejb-ref-name>ejb/UserBean</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      com.website.Statefull.UserBeanLocal
      </ejb-local-ref>

      </web-app>

      jboss complains:

      org.jboss.deployment.DeploymentException: Failed to parse WEB-INF/web.xml; - nes
      ted throwable: (org.jboss.deployment.DeploymentException: expected one local-hom
      e tag)
      at org.jboss.web.AbstractWebContainer.parseMetaData(AbstractWebContainer
      .java:755)
      at org.jboss.web.AbstractWebContainer.init(AbstractWebContainer.java:356
      )

      So I'm guessing it's complaining about tag and it expects <local-home> tag (priori to ejb 3?).
      But I don't understand why, I set the id="WebApp_ID" version="2.5".

      Can anybody tell me what I'm doing wrong?
      Thanks!

        • 1. Re: EJB3 <ejb-local-ref> not working
          wayne baylor Apprentice

          you will also need a jboss-web.xml to map "ejb/UserBean" to the global JNDI name for com.website.Statefull.UserBeanLocal.

          • 2. Re: EJB3 <ejb-local-ref> not working
            Radu Cirstoiu Newbie

            Ok, I added a jboss-web.xml :

            <?xml version="1.0" encoding="UTF-8"?>
            <jboss-web>
            <ejb-local-ref>
            <ejb-ref-name>ejb/UserBean</ejb-ref-name>
            <ejb-ref-type>Session</ejb-ref-type>
            com.website.Statefull.UserBeanLocal
            </ejb-local-ref>
            </jboss-web>

            But now, the exception changes to "org.jboss.deployment.DeploymentException: expected one local-home tag" .
            Any other idea?
            Thanks!

            • 3. Re: EJB3 <ejb-local-ref> not working
              Radu Cirstoiu Newbie

              I fixed it, and in case anybody stumbles across this problem here's what I found:

              1.Jboss doesn't fully support version 2.5 so, in web.xml you should add both and <local-home> to point to the same thing(though I think <local-home> should be added just so the parser won't yell something's wrong)
              2. in jboss-web.xml you should also add <local-jndi-name> which should be something like YourApp/YourBean/local -- which tells jboss -- map the bean YourApp/YourBean/local (proprietary jboss naming format) to java:/comp/env/ejb/YourBean (if you set your <ejb-ref-name> to ejb/YourBean)