CDI Ambiguous dependencies
I had very similar problem, and I got some offline help. My problem was that where my service was, it was included in a deployed ear AND in my web project as well. It was an accidental duplication, drop one out, and it will work if it is your case as well.
here on the following picture I had the esb_khr inside the esb_khr_web, I removed. In eclipse: go to properties and deployment assembly.
I'm not an expert but I had a similar problem, and I fixed it in simpler way, by annotating the bean itself with @Alternative
, so that the Producer is favored. Could be I'm missing some side effects but this worked as far as I could see / needed.
This is because CDI searches for beans by type and your entity and the producer method return the same type. That's why it is ambiguous.
You need to define a new qualifier and annotate it with your producer method.
@Qualifier
@Retention(RUNTIME)
@Target({METHOD, FIELD, PARAMETER, TYPE})
public @interface CurrentUser {
}
Add this annotation to your producer method:
@Named @Produces @CurrentUser @LoggedIn @SessionScoped
public MyUser getCurrentUser() {return user;}