1

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

}
Jens Piegsa
  • 7,399
  • 5
  • 58
  • 106
user3515460
  • 159
  • 1
  • 13
  • If you are using guava, please update to latest guava version, use latest CDI (weld) and in your beans.xml specify ```bean-discovery-mode="annotated"``` – maress Nov 23 '15 at 07:47
  • @maress seems to have a good point. Set is coming from Guava, and there is this famous issue with Guava and CDI, for which a maintenance release of CDI specification was released. More details about issue with guava here: https://code.google.com/p/guava-libraries/issues/detail?id=1433 – OndroMih Nov 23 '15 at 11:23
  • Possible duplicate of [When adding dependency: CDI deployment failure, Unsatisfied dependencies for type Set with qualifiers @Default](http://stackoverflow.com/questions/30956334/when-adding-dependency-cdi-deployment-failure-unsatisfied-dependencies-for-typ) – Jens Piegsa Nov 23 '15 at 11:52

2 Answers2

0

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.

John Ament
  • 11,595
  • 1
  • 36
  • 45
0

I believe that you are using Google Guava in your project, as @maress hints in his comment. There are 3 possible solutions:

  • downgrade Guava to version 13, which is reported to not have this issue
  • add this beans.xml file inside META-INF directory inside JAR file of Guava
  • upgrade Weld to version 2.2 (or whole Glassfish to 4.1), which implements the maintenance version of CDI 1.2, that fixes the problem with Guava

Background:

Set<Services> is coming from Guava. Guava uses @Inject annotations, plus in this specific case it also uses annotation @Singleton. In CDI 1.1 (Java EE 7), beans annotated with @Singleton are considered automatically as CDI beans, and when CDI computes dependencies for this Guava class, it fails - more details here: code.google.com/p/guava-libraries/issues/detail?id=1433

Adding into guava jar file beans.xml which disables CDI with bean-discovery=none solves the problem, but only for Java EE 7 (on the other hand it makes problems with older CDI mechanism used in Java EE 6). Finally, CDI specification 1.2 removed annotation @Singleton from annotations, which turns classes to CDI beans, which also solves the issue with any version of Guava.

OndroMih
  • 7,280
  • 1
  • 26
  • 44