6 Replies Latest reply on Jul 26, 2013 1:21 AM by Ampie Barnard

    Jboss AS 7 - Injecting cdi bean from different modules

    kymsh2 Newbie

      Hi,

       

      I have a ejb module packaged as jar file and deployed as a module in jboss 7 Module directory. This module has got a bean CDITest and I have created a qualifier annotation @CDITestInect along with a producer method so that I can inject this CDITest bean into any application (i.e ear or war).  Then I have created a Web module deployed as war file. I want to inject CDITest bean into a class in this web module. I have defined the dependency of my ejb module in the jboss-deployment-structure.xml in the WEB-INF of my web module.

       

      <jboss-deployment-structure>
        <deployment>
          <dependencies>
            <module name="com.cditest"/>
          </dependencies>
        </deployment>
      </jboss-deployment-structure>
      
      

       

      I have also created beans.xml in the WEB-INF of my web module to activate the cdi. Note that I have also created a beans.xml in the META-INF of my ejb module. I can refer the CDITest bean in my web module and manually create them using new() without any problem (which proved that its on classpath) but as soon as I try to @Inject CDITest or any other bean from ejb module like,

       

      @Inject @CDITestInject
      CDITest test;
      
      

      server throws the following exception

       

      00:57:09,167 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service jboss.deployment.unit."startup-bean-test.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."startup-bean-test.war".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [CDITest] with qualifiers [@CDITestInject] at injection point [[field] @CDITestInject @Inject com.practice.ods.test.StartupBeanTestServlet.test]
                at org.jboss.as.weld.services.WeldService.start(WeldService.java:83)
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [rt.jar:1.6.0_29]
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.6.0_29]
                at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_29]
      Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [CDITest] with qualifiers [@CDITestInject] at injection point [[field] @CDITestInject @Inject com.practice.ods.test.StartupBeanTestServlet.test]
                at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:275)
                at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:244)
                at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:107)
                at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:127)
                at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:346)
                at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:331)
                at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)
                at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:83)
                at org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
                ... 5 more
      
      

       

       

      Note that CDI Injection works fine if I add the ejb jar in the web module under web-inf/lib . but i prefer not to do so  as the CDITest ejb module will be used by other applications ear or war as well and I would like to keep it a seperate module as per jboss 7 module concept. Is it even possible to make the cdi injection works with this design ? if yes what am i missing ? Any help would be appreciated.