Patan
Patan

Reputation: 17893

Unsatisfied dependencies for type ZZZZ with qualifiers @Default

I am have beans as given below.

@Singleton
@DependsOn("DefaultEmailService")
public class CustomerService implements UserHandlingService {

    private DefaultEmailService mailService;

    @Inject
    public CustomerService(DefaultEmailService mailService) {       
        this.mailService = mailService;
    }
}


@Singleton
@Startup
public class DefaultEmailService implements EmailService {

    public DefaultEmailService() {  
    }
}

I get error like

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type DefaultEmailService with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject public com.project.service.CustomerService(DefaultEmailService)
  at com.project.service.CustomerService.<init>(CustomerService.java:0)

Am I doing any thing wrong.

Upvotes: 4

Views: 3088

Answers (1)

fantarama
fantarama

Reputation: 880

The problem is the @Singleton annotation, that is from javax.ejb and not javax.inject. Using the ejb one and defining the interface your bean is registered on CDI context as the interface, not implementation, change your code:

@Inject
public CustomerService(EmailService mailService) {
    this.mailService = (DefaultEmailService) mailService;
}

Upvotes: 4

Related Questions