Unsatisfied dependencies for type [AbstractFacade<Object>] with qualifiers [@Default] at injection point [[BackedAnnotatedField] on GlassFish 4.0

StackOverflow https://stackoverflow.com/questions/22225146

  •  10-06-2023
  •  | 
  •  

Question

When a JSF managed bean extends an abstract Controller, I get Unsatisfied dependencies exception. I have methods in the AbstractController which I would like to override in the PoliceCaseList Bean. However, I get the exception below: I tried reading here and here , but my situation seems different.

exception

javax.servlet.ServletException: WELD-001408 Unsatisfied dependencies for type [AbstractFacade] with qualifiers [@Default] at injection point [[BackedAnnotatedField] @Inject private ijmiscrudgen.backing.AbstractController.ejbFacade]

root cause

org.jboss.weld.exceptions.IllegalArgumentException: WELD-001408 Unsatisfied dependencies for type [AbstractFacade] with qualifiers [@Default] at injection point [[BackedAnnotatedField] @Inject private ijmiscrudgen.backing.AbstractController.ejbFacade]


@ManagedBean
@ViewScoped
public class PoliceCaseList extends AbstractController<TblCase>{

@Inject
private TblCaseFacade caseFacade;
private TblCasePerson selectedPerson;
private TblCase selected;

@ManagedProperty(value = "#{loginController}")
private LoginController loginController;

/**
 * Creates a new instance of PoliceCaseList
 */
public PoliceCaseList() {
}


Here is the Abstract Controller. This Controller has methods which I always want to override. Beans with annotation @Named extend this controller and there are no complaints but the ones annotated with @ManagedBean get the exception above. How can I extend this AbstractController in my JSF Managed Beans without Unsatisfied dependency complaints?

public abstract class AbstractController<T> {

@Inject
private AbstractFacade<T> ejbFacade;
private Class<T> itemClass;
private T selected;
private Collection<T> items;
private boolean trueOrFalse;
private static int idOfSubmittedRecord;

private enum PersistAction {

    CREATE,
    DELETE,
    UPDATE
}

public AbstractController() {
}
Was it helpful?

Solution

The problem is you are mixing two different dependency injection mechanisms: CDI and JSF managed beans/properties. That is why @Named beans work: this is a CDI annotation, so it follows CDI rules for injection to parent classes. On the contrary, @ManagedBeans live in a separate DI container, that of JSF, and do not care about the CDI annotations.

These two worlds communicate through the @Named annotation. So, what I would do is to make everything CDI and use the @Named beans through EL, as if they were normal JSF managed beans. The problem with this is that CDI does not support the view scope of JSF. This can be solved using e.g. the Deltaspike JSF module.

Bottom line: Make everything CDI. Use @Named instead of @ManagedBean and @Inject instead of @ManagedProperty and Deltaspike JSF module for things like @ViewScoped which are not provided out-of-the-box for CDI.

Some references

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