"com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes" error on Jersey Rest



I know this questions been before on this site but I have taken advice from these pages and haven't been able resolve the problem yet. When trying to run a Rest Web Service using Jersey, I come across the following error message:-


EXCEPTION



javax.servlet.ServletException: Servlet.init() for servlet Jersey REST Service threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:724)


ROOT CAUSE



com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)
com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1359)
com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795)
com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:724)


After doing the reasearch, i have narowed it down to 3 problems:-



  1. Errors within the web.xml.

  2. No resources used within packaged project.

  3. Problems with .jar files.


I have edited the web.xml as much as possible and have gotten nowhere with it. Below is the current web.xml file i am using.



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://ift.tt/ra1lAU" xmlns="http://ift.tt/nSRXKP" xmlns:web="http://ift.tt/LU8AHS" xsi:schemaLocation="http://ift.tt/nSRXKP http://ift.tt/LU8AHS" id="WebApp_ID" version="2.5">
<display-name>com.epware.jersey.book</display-name>
<servlet>
<servlet-name>Jersey REST Service</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.epware.jersey.book.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>


I cannot locate any problems within the linked package. This is probably where the error is but i am struggling to find it myself. Again, the code for this is below.



// Will map the resource to the URL todos
@Path("/books")
public class BooksResource {

@Context
UriInfo uriInfo;
@Context
Request request;


@GET
@Produces(MediaType.TEXT_XML)
public List<Book> getBooksBrowser() {
List<Book> books = new ArrayList<Book>();
books.addAll( BookDao.instance.getModel().values() );
return books;
}

@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public List<Book> getBooks() {
List<Book> books = new ArrayList<Book>();
books.addAll( BookDao.instance.getModel().values() );
return books;
}

@GET
@Path("count")
@Produces(MediaType.TEXT_PLAIN)
public String getCount() {
int count = BookDao.instance.getModel().size();
return String.valueOf(count);
}

@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newBook(
@FormParam("id") String id,
@FormParam("title") String title,
@FormParam("description") String description,
@FormParam("authorFirst") String authorFirst,
@FormParam("authorSecond") String authorSecond,
@FormParam("publisher") String publisher,
@FormParam("publishDate") String publishDate,
@Context HttpServletResponse servletResponse
) throws IOException {
Book book = new Book(id,title,description,authorFirst,authorSecond,publisher,publishDate);
BookDao.instance.getModel().put(id, book);
System.out.println(BookDao.instance.getModel().toString());
servletResponse.sendRedirect("../create_todo.html");
}

@Path("{book}")
public BookResource getBook(
@PathParam("book") String id) {
return new BookResource(uriInfo, request, id);
}

}


I am currently using Jersey jars version 1.18 as shown in the image below:-


External Link to Image : http://ift.tt/1Bymzz8


Any help is greatly appreciated a i am on limited time now to get this done.


No comments:

Post a Comment