简体   繁体   中英

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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM