4 Replies Latest reply on Jun 20, 2012 10:23 AM by gboro54

    @Produces with custom qualifier

    gboro54 Novice

      Is it possible to have a method annotated with a @Produces and a custom qualifier annoation? From my testing it does not seem possible but I am wondering if anyone can point me in a direction to do this?

        • 1. Re: @Produces with custom qualifier
          Ales Justin Master

          This is a common use case, dunno what kind of testing you did, but this should just work.

          • 2. Re: @Produces with custom qualifier
            gboro54 Novice

            ArquillianTest.java

            {code}


            package com.common.handler.impl;

             

             

            import javax.inject.Inject;

             

             

            import junit.framework.Assert;

             

             

            import org.jboss.arquillian.container.test.api.OperateOnDeployment;

            import org.junit.Test;

             

             

             

             

            public class DefaultTradeSideChainProducorTest extends AbstractDataTest {

             

             

                      @Inject

                      @ProcessorChainType(chainType = ChainType.DEFAULT_BASE)

                      private Handler baseProcessor;

             

                      @Inject

                      @ProcessorChainType(chainType = ChainType.DEFAULT_ERROR)

                      private Handler errorProcessor;

             

             

                      @Test

                      @OperateOnDeployment("build-testable-ear")

                      public void testInjected() {

                                Assert.assertNotNull(baseProcessor);

                                Assert.assertNotNull(errorProcessor);

                      }

             

             

            }


            {code}


            HandlerChainProducor.java

            {code}

            @Singleton

            @ConcurrencyManagement(ConcurrencyManagementType.BEAN)

            public class HandlerChainProducor{

             

             

                      @Produces

                      @ProcessorChainType(chainType = ChainType.DEFAULT_BASE)

                      public Handler defaultBaseChain(

                                          @Phase(phase = Phase.BASE) Handler baseHandler,

                                          @Phase(phase = Phase.PERSIST) Handler persistHandler) {

             

                                baseHandler.setNext(persistHandler);

                                return baseHandler;

             

             

                      }

             

                      @Produces

                      @ProcessorChainType(chainType = ChainType.DEFAULT_ERROR)

                      public Handler defaultBaseChain(

                                          @Phase(phase = Phase.ERROR) Handler errorHandler) {

             

                                errorHandler.setNext(null);

                                return baseHandler;

             

             

                      }

            }


            {code}

            The above simple version of what I am trying to do produces the following error

             

            {code}

            Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type [Handler] with qualifiers [@Default] at injection point

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

                      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

             

            {code}

             

             

            Any thoughts for that? Each been is annotated with qualifers at @Named

            • 3. Re: @Produces with custom qualifier
              Ales Justin Master

              Do you have @Qualifier on ProcessorChainType?

              • 4. Re: @Produces with custom qualifier
                gboro54 Novice

                Doh! Darn copy and paste error!!! Thanks!

                Ales Justin wrote:

                 

                Do you have @Qualifier on ProcessorChainType?