When you are working with Jersey REST web services, you would encounter the following exception. This is occurred either of two reasons.
- com.sun.jersey.config.property.packages doesn’t exist in your web.xml.
- com.sun.jersey.config.property.packages included a package path, but that is not included any jersey services.
If you check the above two reasons and resolve it, the below exception will be resolved.
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:99) at com.sun.jersey.server.impl.application.WebApplicationImpl. _initiate(WebApplicationImpl.java:1331) at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700 (WebApplicationImpl.java:168) at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f (WebApplicationImpl.java:774) at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f (WebApplicationImpl.java:770) at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193) at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate (WebApplicationImpl.java:770) at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate (WebApplicationImpl.java:765) at com.sun.jersey.spi.container.servlet.ServletContainer.initiate (ServletContainer.java:489) at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent. initiate(ServletContainer.java:319) at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210) at com.sun.jersey.spi.container.servlet.ServletContainer. init(ServletContainer.java:374) at com.sun.jersey.spi.container.servlet.ServletContainer. init(ServletContainer.java:557) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4149) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4458) at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3190) at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:404) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1309) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor. processChildren(ContainerBase.java:1601) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor. processChildren(ContainerBase.java:1610) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor. processChildren(ContainerBase.java:1610) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor. run(ContainerBase.java:1590) at java.lang.Thread.run(Unknown Source)
The web.xml file would look like this:
web.xml
<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>javabeat.net.jersey</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jersey-serlvet</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping>