Main Tutorials

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 Author

author image
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

Subscribe
Notify of
13 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Ali Saleh
10 years ago

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
10 years ago

You are a life savior.. 🙂

mistr2u
10 years ago

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

Replace

@Path(“/hello”)

with

@Path(“hello”)

it helped in my case:)

Vijay
10 years ago

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.

mak
9 years ago

thanks man i was struck in this for about 1 day

Abhishek
9 years ago

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

Hetal
9 years ago

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
10 years ago

That was helpful. Thank you very much.

Da-woon Yi
11 years ago

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

Conor
11 years ago

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!

Ahmed
12 years ago

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
12 years ago

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:

 


  ReSTWeb
  
		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/*
	

Rajesh V
12 years ago

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 the ejb project as a jar inside lib of my web project its working fine, but If I add the ejb project as J2ee module dependency to web project its working…

Could you please let me know the process of Converting EJB3 session bean into ReST service.

Thanks in Advance!
Rajesh V