What is the usage of this code line in the rest api
Set<Class<?>> resources = new java.util.HashSet<>();
@ApplicationPath("/service")
public class ApplicationConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<>();
System.out.println("REST configuration starting: getClasses()");
//features
//this will register Jackson JSON providers
resources.add(org.glassfish.jersey.jackson.JacksonFeature.class);
//more code.....
}
The Application
class defines the components of a JAX-RS application. Subclasses of Application
can override the getClasses()
to register a set of root resource, provider and feature classes used by the application.
The simplest implementation possible is as following:
@ApplicationPath("api")
public SampleApplication extends Application {
}
In the example above no resources classes or providers are registered, so the JAX-RS runtime will scan the classpath for JAX-RS components annotated with @Path
and @Provider
and will register them automatically.
See this answer for details.
Set<Class<?>>
means a Set
that holds Class
es of unknown types (it's expressed by the ?
wildcard). In The Java Tutorials from Oracle you'll find a whole section about generics. I encourage you to have a look.