0

I have a java EE web application in which a particular injection causes following error:

WELD-001408: Unsatisfied dependencies for type GenericDAO with qualifiers @Default

MyBean

@Stateless
public class MyBean extends CustomBean<Entity> {
...
}

CustomBean

public class CustomBean<T extends Serializable> implements Serializable {
    @Inject
    private GenericDAO<T> genericDAO;
}

GenericDAO

public abstract class GenericDAO<T extends Serializable> implements Serializable {
...
}

The issue appears only if a beans.xml is defined in the application. Deleting this, solves also the issue. In my case beans.xml is needed. Also when removing the GenericDAO<T> genericDAO; injection from the CustomBean, the error does not appear anymore. Also the rest of my injection in other classes, seem to work without any issue.

I've tried to solve that by creating an interface of GenericDAO and inject the interface instead. Also tried to with several anotations like @Local , @Dependent etc but i stumble upon different errors every time.

Stephan
  • 696
  • 15
  • 37
  • What does the implementation of `GenericDAO` look like? CDI can't inject an abstract instance without knowing the implementation. – James R. Perkins Aug 31 '21 at 19:48
  • GenericDAO contains methods persistence methods common for most of my entities. As i mentioned though, i tried extracting an interface out of GenericDAO and injecting this instead, without much luck – Stephan Sep 01 '21 at 05:15
  • CDI has to know the implementation for the `GenericDAO` whether it's abstract or an interface. If you've got several types that extend or implement `GenericDAO` you need to tell CDI which one you want injected. CDI can't really know or make the guess. – James R. Perkins Sep 01 '21 at 18:15
  • But isn't that information passed with the parameter in the injection on private GenericDAO genericDAO; Unless i understood something else. Yes, i have many other DAO that extend the GenericDAO. E.g. : public class SampleDAO extends GenericDAO – Stephan Sep 02 '21 at 08:50
  • I'm not a CDI expert, however I don't think it considers generic types when looking for a match. I'm not really sure how that could work TBH. – James R. Perkins Sep 02 '21 at 15:13

0 Answers0