Unsatisfactory dependencies for type ZZZZ with @Default qualifiers
I have beans as shown 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 am getting an 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)
I am doing something wrong.
+3
source to share
1 answer
The problem is with annotations @Singleton
, that is, from javax.ejb
, not javax.inject
. Using ejb one and defining an interface, your bean is registered in the CDI context as an interface, not an implementation, change your code:
@Inject
public CustomerService(EmailService mailService) {
this.mailService = (DefaultEmailService) mailService;
}
+3
source to share