1

Getting following exception while injecting beans in scenario whose answer not able to found and beans.xml is included:

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type CustomerAgreementDaoImpl with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject public com.evry.integrator.snow.fetch.CustomerAgreementFetcher.customerAgreementDaoImpl
  at com.evry.integrator.snow.fetch.CustomerAgreementFetcher.customerAgreementDaoImpl(CustomerAgreementFetcher.java:0)

        at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:378)
        at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:290)

Following is code structure:

Beans.xml in /WEB-INF

<beans xmlns="http://java.sun.com/xml/ns/javaee" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                           http://java.sun.com/xml/ns/javaee/beans_1_1.xsd"
       version="1.1" bean-discovery-mode="all"> 
</beans>

Interfaces

public interface GenericDao<T, PK> {

public interface CustomerAgreementDao extends GenericDao<CustomerAgreement, Long>{

Absract Class implementing Generic DAO

public abstract class GenericDaoImpl<T, PK> implements GenericDao<T, PK> {

@PersistenceContext(unitName = "IntegratorMasterdataDS")
protected EntityManager em;

Main Implementation

@Stateless
public class CustomerAgreementDaoImpl extends GenericDaoImpl<CustomerAgreement, Long> implements CustomerAgreementDao {

public CustomerAgreementDaoImpl() {
    System.out.println("CustomerAgreementDaoImpl");
}

Dao used in Service class

@Stateless
public class CustomerAgreementFetcher {

    @Inject
    public CustomerAgreementDaoImpl customerAgreementDaoImpl;

Main Scheduler loading all of above

@Startup
@Singleton
@AccessTimeout(value = 5, unit = TimeUnit.MINUTES)
public class WPoller {
    @Inject
    CustomerAgreementFetcher customerAgreementFetcher;
fatherazrael
  • 5,511
  • 16
  • 71
  • 155

1 Answers1

1

Can you update the field's type to be the CustomerAgreementDao interface?

@Stateless
public class CustomerAgreementFetcher {

    @Inject
    public CustomerAgreementDao customerAgreementDao;

Related topic: Is it possible to inject EJB implementation and not its interface using CDI?

Petr Aleksandrov
  • 1,434
  • 9
  • 24
  • Lolzzz... I just accomplished it in similar way and it worked :D Well thanks for answer. – fatherazrael Dec 02 '19 at 08:28
  • Another question coming in mind that if i create two implementations of those Abstractclass/interface then how it works? Then which implementation it will pick by default and how can we specify particular implementation:? – fatherazrael Dec 02 '19 at 08:37
  • If you have multiple implementations, WELD will throw "Ambiguous dependencies..." exception. This possible can be handled by [cdi qualifiers](https://docs.jboss.org/weld/reference/latest/en-US/html/injection.html#_qualifier_annotations) – Petr Aleksandrov Dec 02 '19 at 08:54
  • O just seen it appears not user friendly as of Spring where we can mention qualifier name. So for each qualifier i need to create one interface. – fatherazrael Dec 02 '19 at 09:12
  • `javax.inject.Named` is a qualifier. – Laird Nelson Dec 06 '19 at 01:05
  • what happens in the case you are not using interfaces and you want to inject the bean itself ? Won't the extention to the genericDAO cause an issue in this case? – Stephan Aug 31 '21 at 08:57