6 Replies Latest reply on Aug 24, 2018 4:56 AM by gergely.hegyi

    WELD-000132: Disabled alternative

    gergely.hegyi

      I have an implementation class, and a Mock class for that implementation. Both class implement an interface.

       

      Server: wildfly-8.2.0.Final (with 9.0 same result)

       

      Interface:

      public interface Validator {

       

           dosomething...

      }

       

      Primary implementation:

      @Stateless
      public class ValidatorBean implements Validator {

           dosomething...

      }

       

      Mock:

      @Alternative

      public class MockValidatorBean implements Validator {

           dosomething...

      }

       

      And when I try to use a mock (create a row in beans.xml):

       

      <alternatives>

        <class>com.package.MockValidatorBean</class>

        </alternatives>

       

      It doesn't work. I tried to debug, but there are no information. I see some debug log, for recognised alternatives from beans.xml. But the primary class has been injected.

       

      I try to use stereotype:

      @Stereotype
      @Alternative
      @Target( { TYPE, METHOD, FIELD })

      @Retention(RUNTIME)

      public @interface NoValidation {

      }

       

      Changed mock class:

      @NoJWTValidation

      public class MockValidatorBean implements Validator {

           dosomething...

      }

       

      beans.xml:

      <alternatives>
        <stereotype>com.package.NoValidation</stereotype>
      </alternatives>

       

      And I got one relevant line:

      DEBUG [org.jboss.weld.Bootstrap] (MSC service thread 1-8) WELD-000132: Disabled alternative (ignored): Managed Bean [class com.package.MockValidatorBean] with qualifiers [@Any @Default]

       

      When i put the @Prioroty(300) into the Mock class, it works.

       

      How can I fix this issue?

        • 1. Re: WELD-000132: Disabled alternative
          mkouba

          Hi Hegyi,

          when you use beans.xml to enable/select an alternative it's only selected locally, i.e. in the bean archive where the beans.xml resides. @Priority, on the other hand, selects the alternative globally, i.e. the alternative is selected for the application. How does you deployment look like? Is the beans.xml located in the same bean archive as the bean which attempts to inject a Validator?

          • 2. Re: WELD-000132: Disabled alternative
            gergely.hegyi

            Hi Martin,

             

            Thank you for your answer.

            My answer is: No. The interface, primary bean and mock is in Common.jar. The beans.xml in war.

            I tried that way: The interface, primary bean is in Common.jar. The beans.xml and mock are in war. But it doesn't work too.

             

            We have many maven profile in WAR build. And some profile use different alternative set. And thees profiles copy own beans.xml to the right place. This is why beans.xml located in war package.

             

            G.

            • 3. Re: WELD-000132: Disabled alternative
              manovotn

              Hi,

               

              since the enablement via beans.xml is on a per bean archive basis, you need to have that alternative defined in the beans.xml which resides in the same archive as the bean which does @Inject Validator.

              Otherwise you need to use priority or probably leverage extensions in some way.

               

              Where does the bean injecting Validor reside? In common.jar?

              • 4. Re: WELD-000132: Disabled alternative
                gergely.hegyi

                yes, in common.jar as well.

                • 5. Re: WELD-000132: Disabled alternative
                  manovotn

                  I see, that won't work. So you can either:

                   

                  1) Keep the beans as they are and move your current beans.xml enablement into common.jar as well

                   

                  2) Keep beans.xml in WAR but move bean which does @Inject Validator into WAR as well.

                   

                  3) Use @Priority as a means of enabling alternative (but that has global effect)

                  • 6. Re: WELD-000132: Disabled alternative
                    gergely.hegyi

                    Thanks you for your answers guys!

                    Cheers!