6
votes

I am new to work on the creation of web services(Restful api). following a simple tutorial of Java Brains for Restful web services. I am Getting the error which says something like "Unsatisfied dependencies for type Set with qualifiers @Default"

I have searched for different questions here, have tried below things:

  1. downloaded new server and connected it to my project and removed old server.
  2. updated guava dependencies and added its jar to my project.

still facing the error.

below is the server error log.

Severe: Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type Set with qualifiers @Default at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject com.google.common.util.concurrent.ServiceManager(Set) at com.google.common.util.concurrent.ServiceManager.(ServiceManager.java:0) org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type Set with qualifiers @Default at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject com.google.common.util.concurrent.ServiceManager(Set) at com.google.common.util.concurrent.ServiceManager.(ServiceManager.java:0)

this is studentservice class which is providing data.

public class StudentService {
    public List<Student> getAllData() {
        Student s1 = new Student(1, "Sagar", 20);
        Student s2 = new Student(2, "Puneet", 23);
        List<Student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        return list;
    }
}

Below is my api class

@Path("/myfirstapi")
public class MyFirstAPI {
StudentService ss=new StudentService();
@GET
@Produces(MediaType.APPLICATION_XML)
public List<Student> gettext() {
    return ss.getAllData();
    }
}
2
Without any more information like for example the code, it is very hard to give any advice. - hotzst
@hotzst code has been added, please let me know if you require anything else. i am trying to create a basic api example where i am using get method to get the data from studentservice class. - Sagar Khurana

2 Answers

5
votes

The cause of this error is usually a bad version of Guava. You may have a version of Guava < 16. You should check your classpath.

I can see 2 solutions :

  • If you are using CDI (you do not seem to), update Guava version with version >= 16.
  • Else disable CDI (remove beans.xml if present in classpath and disable implicit scanning in you application server).
0
votes

Probably your web server already contains guava library and has no problems with it. So what you need is preventing your guava library from getting into the war file. Some say (Using Jersey 2.1 with CDI), that

simply setting the guava dependency to provided (or test) in maven solves the problem.

I use gradle so I put the dependency into compileOnly set:

compileOnly 'org.glassfish.jersey.core:jersey-client:2.0.1'

First I ran gradle dependencies to find out, what is pulling guava in. Finally I examined my war to confirm guava is no longer there.