Frage

I have the following classes:

public class MyMap extends HashMap {
   public MyMap () { }
   some more methods...
}


@SessionScoped
public ProducerClass implements Serializable {
   @Produces @MyItem  HashMap<A,B> produceItems () { }
}

@Named 
public ConsumerClass {
  @Inject @MyItem HashMap<A,B> property;
}

@Retention(RUNTIME)
public @interface MyItem {
}

I get the error ambiguous injection point at property for MyMap and HashMap form ConsumerClass.

How can it be ? I thought that the injection class is unique given through @MyItem annotation.

War es hilfreich?

Lösung

You have to mark MyItem as a CDI Qualifier, otherwise this annotation will be useless.

@Qualifier
@Retention(RUNTIME)
public @interface MyItem {
}

should do the job.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top