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

Problem

Deploying Jersey REST service, hit following error message on Tomcat.


SEVERE: Servlet /RESTfulExample threw load() exception
com.sun.jersey.api.container.ContainerException: 
	The ResourceConfig instance does not contain any root resource classes.
	
        //... code omitted 

Here’s the web.xml


<web-app ...>

	<servlet>
		<servlet-name>jersey-serlvet</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.mkyong.rest</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>jersey-serlvet</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>

</web-app>

Solution

Many reasons causing this “ResourceConfig” error message. Few solutions that i know :

  1. com.sun.jersey.config.property.packages doesn’t exist in your web.xml.
  2. com.sun.jersey.config.property.packages included a resource that doesn’t include any jersey services. In above case, "com.mkyong.rest” doesn’t contains any jersey services.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
14 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
12 Comment authors
makAbhishekHetalmistr2uAli Saleh Recent comment authors
newest oldest most voted
Ali Saleh
Guest
Ali Saleh

Hi,
Your posts are really very helpful and I refer to them every time and then,

My problem was very simple that I needed to to do “Maven Update Project” because I added the java directory manually so it was not included in the build by Maven.

I thought this may help somebody :)

Regards,
Ali Saleh

Lahiru
Guest
Lahiru

You are a life savior.. :)

mistr2u
Guest
mistr2u

If you still experiencing this issue try to remove “/” from @Path annotaion value:

Replace

@Path(“/hello”)

with

@Path(“hello”)

it helped in my case:)

mak
Guest
mak

thanks man i was struck in this for about 1 day

Abhishek
Guest
Abhishek

Awesome tutorial. :P Any plans to update the project for Jersey 2.0 ?

Hetal
Guest
Hetal

hey i am new to this webservice world. pz guide me. i am getting 400 – no requested resource found error.

My sample class is

package com.exe.testHello;

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.Produces;

import javax.ws.rs.core.MediaType;

@Path(“/hello”)

public class Hello {

public Hello(){

//public contructor

}

// This method is called if TEXT_PLAIN is request

@GET

@Produces(MediaType.TEXT_PLAIN)

public String sayPlainTextHello() {

return “Hello Jersey”;

}

}

my xml is

RestDemo

Jersey REST Service

com.sun.jersey.spi.container.servlet.ServletContainer

com.sun.jersey.config.property.packages

com.exe.testHello

1

Jersey REST Service

/rest/*

Benny Neugebauer
Guest
Benny Neugebauer

That was helpful. Thank you very much.

Da-woon Yi
Guest
Da-woon Yi

There is a typo, jersey-serlvet. It affects nothing.

Conor
Guest
Conor

You are a life saver. This worked perfectly. It turned out that when I renamed one of my packages, I never updated the web.xml file. Thanks a lot!

trackback
JAX-RS Tutorial

[…] Jersey : The ResourceConfig instance does not contain any root resource classes […]

Ahmed
Guest
Ahmed

i have the same probleme , i hava my ejb appl and my web app , in the EJB project i have the session wich i translate them on a REST using JERSEY ,
here i am “The ResourceConfig instance does not contain any root resource classes.”

did you find a solution ?

Rajesh V
Guest
Rajesh V

sorry, i think in my above post I have not provide the java and web.xml code properly. here is the my EJB3.0 session bean which I have converted to Rest Service: package com.dfs.ejb.rest.demo; import javax.ejb.Stateless; import javax.ws.rs.*; /** * Session Bean implementation class NameService */ @Path("name") @Stateless public class NameService implements NameServiceRemote { /** * Default constructor. */ public NameService() { // TODO Auto-generated constructor stub } @GET @Produces("text/html") public String getHtml() { return "Hello Rajesh"; } @PUT @Consumes("text/plain") public void put(String content) { System.out.println("Inside put :"+content); } } here is my web.xml: < ?xml version="1.0" encoding="UTF-8"?> ReSTWeb Jersey REST… Read more »

Rajesh V
Guest
Rajesh V

Hi MK, Thanks for your Post. I am also facing the same problem when I convert the EJB3.0 session bean into ReST service. my session bean: package com.dfs.ejb.rest.demo; import javax.ejb.Stateless; import javax.ws.rs.*; /** * Session Bean implementation class NameService */ @Path(“name”) @Stateless public class NameService implements NameServiceRemote { /** * Default constructor. */ public NameService() { // TODO Auto-generated constructor stub } @GET @Produces(“text/html”) public String getHtml() { return “Hello Rajesh”; } @PUT @Consumes(“text/plain”) public void put(String content) { System.out.println(“Inside put :”+content); } } my web.xml: Jersey REST Service com.sun.jersey.spi.container.servlet.ServletContainer com.sun.jersey.config.property.packages com.dfs.ejb.rest.demo 1 Jersey REST Service /rest/* if I add… Read more »

Vijay
Guest
Vijay

Also ensure that your build classpath entries doesn’t have any error like missing jars etc…
I faced this funny issue and resolved by removing the reference of a missing jar file.