Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The ResourceConfig instance does not contain any root resource classes

Tags:

java

jersey

What's going wrong here?

The ResourceConfig instance does not contain any root resource classes.
Dec 10, 2010 10:21:24 AM com.sun.jersey.spi.spring.container.servlet.SpringServlet initiate
SEVERE: Exception occurred when intialization
com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
        at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:103)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1182)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.access$600(WebApplicationImpl.java:161)
        at com.sun.jersey.server.impl.application.WebApplicationImpl$12.f(WebApplicationImpl.java:698)
        at com.sun.jersey.server.impl.application.WebApplicationImpl$12.f(WebApplicationImpl.java:695)
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:197)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:695)
        at com.sun.jersey.spi.spring.container.servlet.SpringServlet.initiate(SpringServlet.java:117)

Filter:

<filter>
    <filter-name>JerseyFilter</filter-name>
    <filter-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</filter-class>

    <init-param>
        <param-name>com.sun.jersey.config.feature.Redirect</param-name>
        <param-value>true</param-value>
    </init-param>

    <init-param>
        <param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
        <param-value>/views/</param-value>
    </init-param>

    <init-param>
        <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
        <param-value>/(images|css|jsp)/.*</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>JerseyFilter</filter-name>
    <url-pattern>/myresource/*</url-pattern>
</filter-mapping>

Code:

@Path ("/admin")
public class AdminUiResource {

  @GET
  @Produces ("text/html")
  @Path ("/singup")
  public Viewable getSignUp () {
    return new Viewable("/public/signup", "Test");
  }
}
like image 834
cmani Avatar asked Dec 10 '10 18:12

cmani


6 Answers

Have you tried adding

<init-param>
  <param-name>com.sun.jersey.config.property.packages</param-name>
  <param-value>my.package.name</param-value>
</init-param>

to your SpringServlet definition? Obviously replace my.package.name with the package that AdminUiResource is in and make sure it is in the classpath.

like image 73
Mike Avatar answered Nov 09 '22 22:11

Mike


I am new to Jersey - I had the same issue, But when I removed the "/" and just used the @path("admin") it worked.

@Path("admin")
public class AdminUiResource { ... }
like image 20
Anver Sadhat Avatar answered Nov 10 '22 00:11

Anver Sadhat


YOU NEED TO ADD YOUR PACKAGE NAME AT

<init-param>
  <param-name>com.sun.jersey.config.property.packages</param-name>
  <param-value>your.package.name</param-value>
</init-param>

ALSO ONE SILLY THING I HAVE NOTICED,
I Need to refresh my project after MAVEN BUILD else it show me same error.
Please comment If you know reason why we need to refresh project?

like image 32
VeKe Avatar answered Nov 09 '22 23:11

VeKe


This means, it couldn't find any class which can be executed as jersey RESTful web service.

Check:

  • Whether 'com.sun.jersey.config.property.packages' is missing in your web.xml.
  • Whether value for 'com.sun.jersey.config.property.packages' param is missing or invalid (the mentioned package doesn't exists). It should be a package where you have put your POJO classes which runs as jersey services.
  • Whether there exists at least one POJO class, which has a method annotated with @Path attribute.
like image 28
Pawan Avatar answered Nov 10 '22 00:11

Pawan


Your resource package should contain at least one pojo which is either annotated with @Path or have at least one method annotated with @Path or a request method designator, such as @GET, @PUT, @POST, or @DELETE. Resource methods are methods of a resource class annotated with a request method designator. This resolved my issue...

like image 12
hakish Avatar answered Nov 10 '22 00:11

hakish


I ran across this problem with JBOSS EAP 6.1. I was able to deploy my code through eclipse to the JBOSS server but once I attempted to deploy the file as a WAR file to JBOSS I started getting this error.

The solution was configuring the web.xml to work properly with JBOSS by allowing the two to work together.

The following two lines were commented out in web.xml to allow JBOSS to do it's own configurations

<!--  
    <init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>com.your.package</param-value>
</init-param> -->

And then add the following context params after

<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.resources</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.providers</param-name>
    <param-value>false</param-value>
</context-param>
like image 11
Antman06 Avatar answered Nov 09 '22 22:11

Antman06