varren varren - 10 months ago 67
Java Question

How to list all registered JAX-RS Entity Providers in Jersey

Let's suppose i have simple jersey app with embedded jetty Demo project on github and essential code below.

Back in the days with jersey1 i had log messages:

мая 07, 2016 5:05:50 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
мая 07, 2016 5:05:50 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class ru.varren.MyResource
мая 07, 2016 5:05:50 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Provider classes found:
class ru.varren.JsonProvider
мая 07, 2016 5:05:50 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:08 PM'

But now i am trying to work with jersey2 and thiere is no more log info. So, my question is how to list all registered JAX-RS Entity Providers. I don't care much where to list them. In
function or in some
method. Probably i should change something in my setup or put logger boolean, but cant find it.

This is purely for testing purpose. Simple print of all providers classes will be enough for me. Cooler option is to print provider and accosiated

public class MyResource {

@Produces({ MediaType.APPLICATION_JSON })
public Response getPersons() {
return Response.ok("[some data here]").build();


public class MyApplication {

public static void main(String[] args) throws Exception {
URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build();
ResourceConfig config = new ResourceConfig(MyResource.class);
Server server = JettyHttpContainerFactory.createServer(baseUri, config, true);



dependencies {
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.22.2'
compile 'org.glassfish.jersey.containers:jersey-container-servlet-core:2.22.2'
compile ''
compile 'org.glassfish.jersey.containers:jersey-container-jetty-http:2.22.2'

compile 'org.eclipse.jetty:jetty-server:9.1.0.M0'
compile 'org.eclipse.jetty:jetty-servlet:9.1.0.M0'


You can use an ApplicationEventListener, and on INITIAILZATION_FINISHED, you can get a set of resources and providers from the ApplicationEvent. For example

public class ProviderLoggingListener implements ApplicationEventListener {

    public void onEvent(ApplicationEvent event) {
        switch (event.getType()) {
                Set<Class<?>> providers = event.getProviders();
                Set<Class<?>> resources = event.getResources();

    public RequestEventListener onRequest(RequestEvent requestEvent) {
        return null;