9 Replies Latest reply on Dec 5, 2011 10:25 AM by alesj

    WELD Injection problem on AS7

    osnetwork

      Hello everyone,

       

      I'm trying to deploy a CometD application on JBoss AS7. I have added all the jetty required modules and now I have the following code which is causing some problems

      import org.cometd.java.annotation.Service;

       

      @Service

      public class TestService {

       

                private BayeuxServer server = new BayeuxServerImpl();

       

                // @Inject

                // private BayeuxServer server;

      In fact, if I leave the code as it is it doesn't complain, but if I change the server property with the commented part annotated with @Inject I get this error message

      21:44:37,854 INFO  [org.jboss.weld] (MSC service thread 1-5) Starting weld service

      21:44:38,672 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service jboss.deployment.unit."Test.ear".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."Test.ear".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [BayeuxServer] with qualifiers [@Default] at injection point [[field] @Inject private org.test.cometd.service.TestService.server]

                at org.jboss.as.weld.services.WeldService.start(WeldService.java:96)

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]

                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_27]

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_27]

                at java.lang.Thread.run(Thread.java:662) [:1.6.0_27]

      Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [BayeuxServer] with qualifiers [@Default] at injection point [[field] @Inject private org.test.cometd.service.TestService.server]

                at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:274)

                at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:243)

                at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:106)

                at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:126)

                at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:345)

                at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:330)

                at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)

                at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:82)

                at org.jboss.as.weld.services.WeldService.start(WeldService.java:89)

                ... 5 more

       

      21:44:39,054 ERROR [org.jboss.as.deployment] (DeploymentScanner-threads - 1) {"Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"Failed services" => {"jboss.deployment.unit.\"Test.ear\".WeldService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"Test.ear\".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [BayeuxServer] with qualifiers [@Default] at injection point [[field] @Inject private org.test.cometd.service.TestService.server]"}}}}

      What is the reason of this error? I think it is not related to the dependencies since instantiating the class with "new" seems to work.

       

      thanks in advance.

      LM

        • 1. Re: WELD Injection problem on AS7
          nickarls

          Injection is all about two things

           

          a) Having a beans.xml marker file so that the archive is marked as CDI-enabled

          b) Aquiring instances from the container so that injection is performed

           

          Are you green on both accounts? Surely you aren't getting working injection with "new"?

          • 2. Re: WELD Injection problem on AS7
            osnetwork

            Nicklas Karlsson wrote:

             

            Injection is all about two things

             

            a) Having a beans.xml marker file so that the archive is marked as CDI-enabled

            b) Aquiring instances from the container so that injection is performed

             

            Are you green on both accounts? Surely you aren't getting working injection with "new"?

            I do have the beans.xml file.

            The problem seems to be about acquiring the instance of my bean... using @Inject when I'm deploying my application I get this error, while if I use "new" I don't get it.

             

            To be more precise on what is my scenario it can be seen here

             

            http://cometd.org/documentation/2.x/cometd-java/server/services/annotated

             

            Basically the "Inherited Style" service works, while the "Annotated Style" service fail with the previous exception.

            • 3. Re: WELD Injection problem on AS7
              alesj

              Where should BayeuxServer come from?

              Is it a bean, is it produced, ... ?

              • 4. Re: WELD Injection problem on AS7
                osnetwork

                BayeuxServer is part of CometD and as far as I know it gets instanziated through the CometD servlet on the start-up, most likely in the init() method of the servlet.

                • 5. Re: WELD Injection problem on AS7
                  alesj

                  But is it ever made into a CDI bean?

                  • 6. Re: WELD Injection problem on AS7
                    osnetwork

                    I don't know, I was following the documentation from the CometD website and in my project I have just added the beanx.xml file to enable CDI.

                    I have added the manifest entries about the CometD libraries so the dependencies are satisified and I thought these libraries/classes should be available for CDI too. isn't it like that?

                    • 7. Re: WELD Injection problem on AS7
                      alesj

                      I have added the manifest entries about the CometD libraries so the dependencies are satisified and I thought these libraries/classes should be available for CDI too. isn't it like that?

                      The bins/classes are available, but that doesn't make those classes beans by default. ;-)

                      Either those lib need beans.xml or CDI Extension present.

                      I suggest you read some docs on CDI before using it as well. :-)

                      • 8. Re: WELD Injection problem on AS7
                        osnetwork

                        I'm not sure if that's the best approach, but since I dont want to touch the CometD libraries I have solved using @Alternative annotation.

                        @Alternative

                        public class InjectableBayeuxServer extends BayeuxServerImpl {

                         

                        }

                        and I have added it in the beans.xml

                        <?xml version="1.0" encoding="UTF-8"?>

                        <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                                  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd">

                                      <alternatives>

                                                <class>org.test.cometd.service.InjectableBayeuxServer</class>

                                      </alternatives>

                        </beans>

                        now the BayeuxServerImpl gets injected.

                        1 of 1 people found this helpful
                        • 9. Re: WELD Injection problem on AS7
                          alesj

                          You can just have a producer:

                           

                          public class BSP {

                              @ApplicationScoped

                             public BayeuxServer produceServer() {

                                   return new BayeuxServerImpl();

                              }

                          }