I have been creating some REST services with Jersey, and I started getting this error

com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.

I have searched for a while to find any reference to this error without luck.

But finally, I found the issue.

I am using glassfish 3.2 and Jersey 1.6 and I assumed, based on documentation that this was valid:

@Singleton
public class UserResource {

    @Inject
    public UserDao userDao;

    @GET
    @Path("customers/{username}")
    @Produces({ MediaType.TEXT_XML })
    public Customer findCustomer(@PathParam("username") String username) {

        Customer customer = userDao.findCustomer(username);
        return customer;
    }

This is not the case. you MUST have a root @Path annotation as like this:

@Singleton
@Path("customers")
public class UserResource {

    @Inject
    public UserDao userDao;

    @GET
    @Path("{username}")
    @Produces({ MediaType.TEXT_XML })
    public Customer findCustomer(@PathParam("username") String username) {

        Customer customer = userDao.findCustomer(username);
        return customer;
    }

Once I changed this the error was resolved.

Mick Knutson

Java, JavaEE, J2EE, WebLogic, WebSphere, JBoss, Tomcat, Oracle, Spring, Maven, Architecture, Design, Mentoring, Instructor and Agile Consulting. http://www.baselogic.com/blog/resume

View all posts

Java / JavaEE / Spring Boot Channel

BLiNC Supporters

BLiNC Adsense

Archives

Newsletter