4 Replies Latest reply on May 31, 2016 9:18 AM by caarlos0

    @Inject @Any does not work with @Stateless beans anymore

    caarlos0

      I had the following code running in JBoss AS:

       

       

      @ApplicationScoped
      public class ReportGeneratorFactory {
       @Any
       @Inject
       private Instance<ReportGenerator> reportGenerators;
      
      

       

      And the implementations are all like:

      @Stateless
      @ReportGeneratorQualifier(ReportGeneratorType.DAILY_CASH_FLOW)
      public class DailyCashFlowReportGenerator implements ReportGenerator {
      
      

       

      And:

       

      @Stateless
      @ReportGeneratorQualifier(ReportGeneratorType.SALE_PER_SELLER)
      @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
      public class SalePerSellerReportGenerator extends AbstractSaleReportGenerator {
      

       

      The interface is as simple as

       

      public interface ReportGenerator {
          GeneratedReport generate(MandatoryReportGeneratorFilter filter) throws ReportGeneratorException;
      }
      


       

      But Wildfly 9 can't inject those beans:

      org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308: Unable to resolve any beans for Type: interface com.foo.reportgenerator.ReportGenerator; Qualifiers: [@javax.enterprise.inject.Any(), @com.foo.reportgenerator.ReportGeneratorQualifier(value=ITEM_SALE_PER_CUSTOMER)]

       

      I can't just remove the `@Stateless` annotation because there are some `@TransactionAttribute` annotations and stuff.

       

      What is the easy way out of this? Can I update maintaining the same behavior?

       

      Thanks

        • 1. Re: @Inject @Any does not work with @Stateless beans anymore
          nickarls

          Where does @com.foo.reportgenerator.ReportGeneratorQualifier(value=ITEM_SALE_PER_CUSTOMER) come from as it looks like it's included in the match(?)

          • 2. Re: @Inject @Any does not work with @Stateless beans anymore
            caarlos0

            Yeah, it happens for all impls apparently.

             

            Anyways, the impl is like this:

             

             

            @Stateless

            @ReportGeneratorQualifier(ITEM_SALE_PER_CUSTOMER)

            public class ItemSalePerCustomerReportGenerator extends AbstractReportGenerator {

              @EJB

              protected SaleItemsReportService saleItemsReportService;

              @EJB

              protected NotaFiscalItemsReportService notaFiscalItemsReportService;

            • 3. Re: @Inject @Any does not work with @Stateless beans anymore
              nickarls

              Lets assume the interface and factory is OK. Take out all the implementations. Do a simple POJO

               

              public class PojoReportGenerator implements ReportGenerator {

              ...

              }

               

              Does the injection see one implementation?

               

              Add a

               

              public class PojoReportGenerator2 implements ReportGenerator {

              ...

              }

               

              Does the injection see two implementations?

               

              Make both implementations @Stateless

               

              Still two implementations? Then add qualifiers etc. Also, make sure you use correct javax. imports for annotations and qualifiers etc.

              • 4. Re: @Inject @Any does not work with @Stateless beans anymore
                caarlos0

                I think the problem may be with the .ear deployment.

                 

                tree -L 1

                .

                ├── META-INF

                ├── foo-business.jar

                ├── foo-public.war

                ├── foo-presentation.war

                └── lib

                The foo-business.jar has the classes cited, and the foo-presentation.war has a @Resource that injects the ReportGeneratorFactory.

                 

                The application.xml looks like:

                 

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

                <!DOCTYPE application PUBLIC

                "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"

                "http://java.sun.com/dtd/application_1_3.dtd">

                <application>

                <display-name>foo</display-name>

                <module>

                   <web>

                     <web-uri>foo-public.war</web-uri>

                     <context-root>/pub</context-root>

                   </web>

                </module>

                <module>

                   <web>

                     <web-uri>foo-presentation.war</web-uri>

                     <context-root>/</context-root>

                   </web>

                </module>

                <module>

                   <ejb>foo-business.jar</ejb>

                </module>

                </application>

                 

                beans.xml are all empty.

                 

                jboss-ejb-client.xml is:

                 

                <?xml version="1.0"?>

                <jboss-ejb-client xmlns="urn:jboss:ejb-client:1.0">

                    <client-context>

                        <ejb-receivers local-receiver-pass-by-value="false"/>

                    </client-context>

                </jboss-ejb-client>

                 

                Maybe something has changed in the ear deployment in wildfly 9?