Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top