2 Replies Latest reply on Apr 7, 2011 8:24 PM by rop

    EJB3 and Struts2 with CDI

    rop Newbie

      Hi,

       

      Under Jboss 6, I am trying to make a Stateless EJB accessible in a Struts2 Action-class with CDI.

       

      They are in an ejb-jar and war-app, packed into a common ear-file.

       

      Following some examples I found, I created an empty beans.xml in the WEB-INF folder,

      I annotated the EJB-class with

        @Stateless @Named("myEjb") public class MyEjb ...

      and in the Action-class I try

        @Inject MyEjb myEjbM;

       

      Apparanetly, this is not enough, since at deploy-time I get the error below.

      Looks like there is some BeanManager item missing in the JNDI-context.

       

      How do I get it in there?

      Any clues?

       

        DEPLOYMENTS MISSING DEPENDENCIES:

        Deployment "jboss-switchboard:appName=foobar-ear-0.0.1,module=foobar-webapp-0.0.1"

          is missing the following dependencies:

           Dependency "java:global/cdi/foobar-ear-0.0.1/foobar-webapp-0.0.1/BeanManager"

            (should be in state "Installed", but is actually in state "** NOT FOUND

           Depends on 'java:global/cdi/foobar-ear-0.0.1/foobar-webapp-0.0.1/BeanManager' **")

        Deployment "jboss.web.deployment:war=/foobar-webapp" is missing the following dependencies:

          Dependency "vfs:///C:/program1/jboss6/server/default/deploy/foobar-ear-0.0.1.ear_WeldBootstrapBean"

          (should be in state "Create", but is actually in state "**ERROR**")

        • 1. Re: EJB3 and Struts2 with CDI
          rop Newbie

          I think this error was, because you also need an empty beans.xml in the ejb-jar.

          So I fixed that, but then got the errors below.

           

          What is actually required for these @Named and @Inject annotations to work between two different modules in the same ear-file ?

           

          DEPLOYMENTS MISSING DEPENDENCIES:

            Deployment "jboss-injector:topLevelUnit=foobar-ear-0.0.1.ear,unit=foobar-ejbapp-0.0.1.jar,bean=FoobarMgr,interceptor=org.jboss.weld.integration.ejb.SessionBeanInterceptor" is missing the following dependencies:

              Dependency "<UNKNOWN jboss-injector:topLevelUnit=foobar-ear-0.0.1.ear,unit=foobar-ejbapp-0.0.1.jar,bean=FoobarMgr,interceptor=org.jboss.weld.integration.ejb.SessionBeanInterceptor>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'jboss-switchboard:appName=foobar-ear-0.0.1,module=foobar-ejbapp-0.0.1,name=FoobarMgr' **")

            Deployment "jboss-injector:topLevelUnit=foobar-ear-0.0.1.ear,unit=foobar-ejbapp-0.0.1.jar,bean=FoobarMgr,interceptor=org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor" is missing the following dependencies:

              Dependency "<UNKNOWN jboss-injector:topLevelUnit=foobar-ear-0.0.1.ear,unit=foobar-ejbapp-0.0.1.jar,bean=FoobarMgr,interceptor=org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'jboss-switchboard:appName=foobar-ear-0.0.1,module=foobar-ejbapp-0.0.1,name=FoobarMgr' **")

            Deployment "jboss-switchboard:appName=foobar-ear-0.0.1,module=foobar-ejbapp-0.0.1,name=FoobarMgr" is missing the following dependencies:

              Dependency "java:global/cdi/foobar-ear-0.0.1/foobar-ejbapp-0.0.1/BeanManager" (should be in state "Installed", but is actually in state "** NOT FOUND Depends on 'java:global/cdi/foobar-ear-0.0.1/foobar-ejbapp-0.0.1/BeanManager' **")

            Deployment "jboss-switchboard:appName=foobar-ear-0.0.1,module=foobar-webapp-0.0.1" is missing the following dependencies:

              Dependency "java:global/cdi/foobar-ear-0.0.1/foobar-webapp-0.0.1/BeanManager" (should be in state "Installed", but is actually in state "** NOT FOUND Depends on 'java:global/cdi/foobar-ear-0.0.1/foobar-webapp-0.0.1/BeanManager' **")

            Deployment "jboss.j2ee:ear=foobar-ear-0.0.1.ear,jar=foobar-ejbapp-0.0.1.jar,name=FoobarMgr,service=EJB3" is missing the following dependencies:

              Dependency "<UNKNOWN jboss.j2ee:ear=foobar-ear-0.0.1.ear,jar=foobar-ejbapp-0.0.1.jar,name=FoobarMgr,service=EJB3>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'jboss-injector:bean=FoobarMgr,interceptor=org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor,topLevelUnit=foobar-ear-0.0.1.ear,unit=foobar-ejbapp-0.0.1.jar' **")

              Dependency "<UNKNOWN jboss.j2ee:ear=foobar-ear-0.0.1.ear,jar=foobar-ejbapp-0.0.1.jar,name=FoobarMgr,service=EJB3>" (should be in state "Installed", but is actually in state "** UNRESOLVED Demands 'jboss-injector:bean=FoobarMgr,interceptor=org.jboss.weld.integration.ejb.SessionBeanInterceptor,topLevelUnit=foobar-ear-0.0.1.ear,unit=foobar-ejbapp-0.0.1.jar' **")

            Deployment "jboss.j2ee:ear=foobar-ear-0.0.1.ear,jar=foobar-ejbapp-0.0.1.jar,name=FoobarMgr,service=EJB3_endpoint" is missing the following dependencies:

              Dependency "jboss.j2ee:ear=foobar-ear-0.0.1.ear,jar=foobar-ejbapp-0.0.1.jar,name=FoobarMgr,service=EJB3" (should be in state "Installed", but is actually in state "PreInstall")

            Deployment "jboss.web.deployment:war=/foobar-webapp" is missing the following dependencies:

              Dependency "vfs:///C:/program1/jboss6/server/default/deploy/foobar-ear-0.0.1.ear_WeldBootstrapBean" (should be in state "Create", but is actually in state "**ERROR**")

          • 2. EJB3 and Struts2 with CDI
            rop Newbie

            Still didnt get EJB3 dependency-injection to work with Struts2 action-classes.

             

            The main difference to a plain servlet, is that the action-classes in Struts2

            are created on-the-fly (new myActionclass()) everytime a request comes in,

            and @EJB doesnt work for such classes.

             

            Currently, as a work-around, I just do jndi context-lookup to get the EJB3 instead.

             

            But I read somewhere that CDI should be able to handle this.

            Is that correct?

             

            Any input still appreciated!

             

            Thanx,