I have a @SessionScoped @Named
bean with a @Producer
method for a user object:
@Named @SessionScoped
public class UserBean implements S
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;}