glassfish
  1. glassfish
  2. GLASSFISH-20853

Alternatives are not enabled using beans.xml

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Works as designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: cdi
    • Labels:
      None

      Description

      Here is beans.xml:

      <beans
      xmlns="http://xmlns.jcp.org/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
      http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
      bean-discovery-mode="all">
      <alternatives>
      <class>org.javaee7.cdi.alternatives.FancyGreeting</class>
      </alternatives>
      </beans>

      Beans marked with @Alternative are:

      @Alternative
      public class SimpleGreeting implements Greeting {

      @Override
      public String greet(String name)

      { return "Hello " + name; }

      }

      and

      @Fancy
      @Alternative
      public class FancyGreeting implements Greeting {

      @Override
      public String greet(String name)

      { return "Nice to meet you, hello" + name; }

      }

      Complete sample at:

      https://github.com/arun-gupta/javaee7-samples/tree/master/cdi/alternatives

        Activity

        Hide
        jjsnyder83 added a comment -

        This is expected behaviour. SimpleGreeting is not a selected alternative (i.e. disabled bean). FancyGreeting is selected but has a qualifier specified (@Fancy). TestServlet has an injection point "@Inject Greeting greeting", the required bean type is Greeting the required qualifier @Default. FancyGreeting does not satisfy this IP (it only has @Any and @Fancy) -> unsatisfied dependency.

        Show
        jjsnyder83 added a comment - This is expected behaviour. SimpleGreeting is not a selected alternative (i.e. disabled bean). FancyGreeting is selected but has a qualifier specified (@Fancy). TestServlet has an injection point "@Inject Greeting greeting", the required bean type is Greeting the required qualifier @Default. FancyGreeting does not satisfy this IP (it only has @Any and @Fancy) -> unsatisfied dependency.

          People

          • Assignee:
            jjsnyder83
            Reporter:
            arungupta
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: