2 Replies Latest reply on Jul 30, 2011 8:58 AM by skroll

    CDI/EJB Injection in EAR Deployments

    skroll

      I think this may be a bug, but I may be doing something wrong here. Here is my application:

       

      javaee-ear.ear/

           lib/javaee-dao.jar - POJO CDI with beans.xml in META-INF

           lib/javaee-dao-impl.jar - POJO CDI with beans.xml in META-INF

           javaee-web.war

           javaee-ejb.jar - EJB

       

      Now, I have a EJB in javaee-ejb.jar that uses @Inject to pull a dependency from javaee-dao-impl.jar. However, every time I try to use it, the depedency is null and I get a NullPointerException.

       

      What is weird, if I had get rid of the ear, put all the jars in the WAR's WEB-INF/lib and deploy it by itself, the application works fine.

       

      Is there an issue when it comes to EAR deployments, or am I missing something?

        • 1. Re: CDI/EJB Injection in EAR Deployments
          gonne

          I would say you have to add META-INF/beans.xml to your javaee-ejb.jar, otherwise it is not scanned for CDI annotations.

           

          Regards,

          Gonne

          • 2. Re: CDI/EJB Injection in EAR Deployments
            skroll

            If I add beans.xml to the EJB jar, I get:

             

            javax.servlet.ServletException: java.lang.IllegalStateException: Failed to construct component instance

            javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)

            org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67)

             

            It's odd because in a plain WAR deployment it works just fine.