4 Replies Latest reply on Feb 19, 2015 7:12 AM by emilyj

    Implicit bean archive

    emilyj

      For any implicit bean archive, the api javadoc is not clear about the return of getBeanClasses() on BeanDeploymentArchive interface

      /**

           * Gets all classes in the bean deployment archive

           *

           * @return the classes, empty if no classes are present

           */

          Collection<String> getBeanClasses();

      Does the collection<String> getBeanClasses() only contain

      1)the bean classes? In this case, I need to scan the archive and find out the set of beans in the archive and then create DeploymentBeanArchive object with just these set of bean classes

      or

      2)every class in this archive if a bean defining annotation is found? In this case, I need to scan the archive and stop once I have found a bean defining annotation.

       

      Please confirm.

      Thanks

      Emily

        • 1. Re: Implicit bean archive
          jharting

          Hi Emily,

           

          the Javadoc should be updated. The expected behavior is described here: http://docs.jboss.org/weld/javadoc/2.2/weld-spi/org/jboss/weld/bootstrap/api/CDI11Bootstrap.html

          This is the relevant part:

           

          For each implicit bean archive the integrator creates an instance of BeanDeploymentArchive representing this archive. The BeanDeploymentArchive.getBeanClasses() of the bean archive returns all the types found in the archive which are annotated with a bean defining annotations or are Session bean definitions. Filtering rules (BeansXml.getScanning()) are not required to be applied by the integrator. The BeanDeploymentArchive.getEjbs() method returns a collection of EJB descriptors for Session beans present in the archive.

          • 2. Re: Re: Implicit bean archive
            emilyj

            Thank you Jozef! This is much clearer. I have a question on @Inject on a non-bean archive.

            If I have  a war archive with the bean-discovery-mod="None" specified, am I right to say it can still have @Inject on the EE component classes if the bean it tries to inject is defined in any explicit/implicit archives?

             

            e.g. in a war archive, I have

            public class PassivateTestServlet extends HttpServlet {

            @Inject BeanA beanA;

             

            ...

            }

             

            public class BeanB {

             

            @Inject BeanA beanA;

            ...

            }

             

            In the jarA that the above war can access, I have

            @ApplicationScoped

            public class BeanA {

            ...

            }

            If the jarA is an implict/explicit archive, the injection for the PassivateTestServlet should succeed. However, the injection for BeanB should be null as BeanB in the non-bean archive is not a bean. Please confirm whether my understanding is correct or not.

             

            Please confirm.

            Thanks

            Emily

            • 3. Re: Re: Implicit bean archive
              jharting

              Hi Emily,

               

              this is a corner case not explicitly covered by the specification. I think your approach is reasonable and we do something similar with WildFly.

              • 4. Re: Re: Implicit bean archive
                emilyj

                Thanks you Jozef! It will be helpful if CDI 1.2 or CDI 2.0 spec covers this.