Search code examples
jsfjakarta-eeejbcdi

EJB project throws WELD-001408 Exception: Unsatisfied dependencies


I have created an EJB project with the Eclipse IDE. My Application Server is Glassfish 4. And the database which I'm using is Oracle. Now when I run the code, I got the error message:

org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type Set<Service> with qualifiers @Default at injection point

Look at my codes below.

Customer:

package de.java2enterprise.onlineshop.ejb;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Customer implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;

    private String email;
    private String password;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

RegisterBean:

package de.java2enterprise.onlineshop.ejb;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
public class RegisterBean implements RegisterBeanRemote, RegisterBeanLocal {

    @PersistenceContext
    private EntityManager em;

    public RegisterBean() {
    }

    @Override
    public String persist(String email, String password) {
        Customer customer = new Customer();
        customer.setEmail(email);
        customer.setPassword(password);
        em.persist(customer);
        return email + " persisted";
    }
}

RegisterBeanLocal:

package de.java2enterprise.onlineshop.ejb;

import javax.ejb.Local;

@Local
public interface RegisterBeanLocal {
    public abstract String persist(
            String email,
            String password);
}

RegisterBeanRemote:

package de.java2enterprise.onlineshop.ejb;

import javax.ejb.Remote;

@Remote
public interface RegisterBeanRemote {
    public abstract String persist(
            String email,
            String password);
}

And the last one is my RegisterController which injects the RegisterBeanLocal cass:

package de.onlineshop_web.bean;

import java.io.Serializable;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;

import de.java2enterprise.onlineshop.ejb.RegisterBeanLocal;

@Named
@RequestScoped
public class RegisterController implements Serializable {

    private static final long serialVersionUID = 1L;

    private String email;
    private String password;

    @EJB
    private RegisterBeanLocal registerBeanLocal;

    public String persist() {
        String msg = registerBeanLocal.persist(email, password);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(msg));
        return "register";
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

}

Solution

  • It's unlikely your code actually has a Set<Service> defined in it, or atleast that's the assumption I'm going to work off of.

    This error is ambiguous. However, if you can provide the full details of the exception you receive, rather than stopping at qualifiers @Default at injection point it would help get a clearer solution.

    My hunches:

    You mention an EJB project, however you're defining dependencies on JSF code (javax.faces) in your app. Glassfish won't activate JSF on EJBs deployed directly.

    Now, it could be that you mentioned EJB project, however you're actually deploying a WAR. If that's the case, I would check the WAR for unnecessary dependencies being packaged.