Alex Rivera | Logout

Jersey REST The ResourceConfig instance does not contain any root resource classes

Asked 2011-05-24T13:20:53.423
20

Although this is one ancient question, I still can not find the answer to make this work. Please correct if you find any of my statement is not correct.

I have a Java Face app and use REST for the Web Services. I don't think Face has anything to do with my problem at all. The web.xml is:

<servlet>
    <servlet-name>NDREST</servlet-name>
    <servlet-class>
        com.sun.jersey.spi.container.servlet.ServletContainer
    </servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.bi.nd.webservice</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>NDREST</servlet-name>
    <url-pattern>/nd/*</url-pattern>
</servlet-mapping>

I have quite a few more servlets in the web.xml since is is a Face app with Trinidad, etc.

In the package com.bi.nd.webservice, my resource class is:

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Produces(MediaType.APPLICATION_XML)
@Path("/hello")
public class TransactionResource 
{
public TransactionResource() 
{
}

@GET
@Produces(MediaType.TEXT_PLAIN)
public String itWorks()
{
    return "Get is OK";
}
}

The fact that my class has a @GET is enough to identify itself a resource class.
Let alone all other complexities, I compiled my source code with Ant in Eclipse and I got this error in the catalina.out file:

May 24, 2011 8:48:46 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
     co
Edit
Report

1 Answer

8

I found another reason Jersey could fail to find a root resource. The error message is the same, so I thought it'd be a good reason to document the root cause here in case other people stumble on it.

I have a root resource class that has the following annotations on it:

@Singleton
@Path("/helloWorld")
@Service(...) // my own custom annotation
public class MyRootResource {
...
}

This will cause the root resource scanning within Jersey to fail.

The fix is to change the order of the annotations:

@Service(...) // my own custom annotation
@Singleton
@Path("/helloWorld")
public class MyRootResource {
...
}

This works.

answered 2011-12-16T15:19:23.250

Your Answer