users@jersey.java.net

Re: [Jersey] Error using Jersey 1.0.2 with Spring: The ResourceConfig instance does not contain any root resource classes.

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 08 Apr 2009 11:16:10 +0200

Hi Jalpesh,

See the JavaDoc for the SpringServlet here:

   https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/api/contribs/jersey-spring/com/sun/jersey/spi/spring/container/servlet/package-summary.html

Because you do not have any Spring-managed root resource classes you
need to register resource classes using Jersey. So your web.xml needs
to be:

<web-app>
   <display-name>JSR311 Test Web Application</display-name>

   <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>classpath*:META-INF/spring-*.xml</param-value>
   </context-param>
   <listener>
     <listener-class>
       org.springframework.web.context.ContextLoaderListener
     </listener-class>
   </listener>
   <servlet>
     <servlet-name>JSR311Handler</servlet-name>
     <servlet-
class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</
servlet-class>
     <init-param>
       <param-name>com.sun.jersey.config.property.packages</param-name>
       <param-value>com.clickbank.api</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
     <servlet-name>JSR311Handler</servlet-name>
     <url-pattern>/api/*</url-pattern>
   </servlet-mapping>
</web-app>

If you modify your resource class TestURL to be a Spring-managed
resource class then you do not require the init-param in the web.xml
(you can leave it in if you like, it will not affect functionality but
it just means duplication of work, as Spring already knows the set of
registered beans so Jersey does not need to be configured).

Paul


On Apr 8, 2009, at 2:32 AM, Jalpesh Patadia wrote:

> Hello everyone,
>
> I have been using Jersey 1.0.2 with the tomcat, and everything had
> been working great so far. Then I switched over to using the
> SpringContainer from ServletContainer (replacing the <servlet class>
> in web.xml)
> from :
>
> com.sun.jersey.spi.container.servlet.ServletContainer
>
> to :
>
> com.sun.jersey.spi.spring.container.servlet.SpringServlet
>
> and I’m getting the following error when I start tomcat. :
>
> Apr 7, 2009 6:14:53 PM
> 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
> .WebApplicationImpl.processRootResources(WebApplicationImpl.java:607)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application.WebApplicationImpl.initiate(WebApplicationImpl.java:480)
> at
> com
> .sun
> .jersey
> .spi
> .spring.container.servlet.SpringServlet.initiate(SpringServlet.java:
> 80)
> at
> com
> .sun
> .jersey.spi.container.servlet.WebComponent.load(WebComponent.java:433)
> at
> com
> .sun
> .jersey.spi.container.servlet.WebComponent.init(WebComponent.java:167)
> at
> com
> .sun
> .jersey
> .spi.container.servlet.ServletContainer.init(ServletContainer.java:
> 197)
> at
> org
> .apache
> .catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
> at
> org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:
> 992)
> at
> org
> .apache
> .catalina.core.StandardContext.loadOnStartup(StandardContext.java:
> 4058)
> at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:
> 4371)
> at
> org
> .apache
> .catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
> at
> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:
> 771)
> at
> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
> at
> org
> .apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:
> 627)
> at
> org
> .apache
> .catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
> at
> org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
> at
> org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
> at
> org
> .apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:
> 311)
> at
> org
> .apache
> .catalina
> .util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
> at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
> at
> org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
> at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
> at
> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
> at
> org.apache.catalina.core.StandardService.start(StandardService.java:
> 516)
>
>
> I do not have any beans defined in my spring-applicationContext.xml,
> since I’m not using anything spring related yet. Here’s my web.xml
> and spring-applicationContext.xml, for posterity.
>
>
> web.xml
>
> <web-app>
> <display-name>JSR311 Test Web Application</display-name>
>
> <context-param>
> <param-name>contextConfigLocation</param-name>
> <param-value>classpath*:META-INF/spring-*.xml</param-value>
> </context-param>
> <listener>
> <listener-class>
> org.springframework.web.context.ContextLoaderListener
> </listener-class>
> </listener>
> <servlet>
> <servlet-name>JSR311Handler</servlet-name>
> <servlet-
> class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</
> servlet-class>
> <load-on-startup>1</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>JSR311Handler</servlet-name>
> <url-pattern>/api/*</url-pattern>
> </servlet-mapping>
> </web-app>
>
> spring-applicationContext.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:aop="http://www.springframework.org/schema/aop"
> xmlns:util="http://www.springframework.org/schema/util"
> xmlns:seam="http://jboss.com/products/seam/spring-seam"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:tx="http://www.springframework.org/schema/tx"
> xmlns:jee="http://www.springframework.org/schema/jee"
> xsi:schemaLocation="http://www.springframework.org/schema/
> beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
> http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
> http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
> http://www.springframework.org/schema/
> util http://www.springframework.org/schema/util/spring-util-2.0.xsd
> http://jboss.com/products/seam/spring-
> seam http://jboss.com/products/seam/spring-seam-2.0.xsd
> http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
> ">
>
>
> </beans>
>
>
> My HelloWorldResource:
>
>
> package com.clickbank.api;
>
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
>
> @Path("/test")
> public class TestURL
> {
> @GET
> public String testMe()
> {
> return "Hello There!";
> }
> }
>
>
> I’d really appreciate if somebody could help me getting this
> resolved. Once I can get spring working with jersey then I can start
> using other aspects of my projects with jersey, but this issue has
> been hampering my progress. I apologize if I’m doing something
> stupid, as I’m just getting started with jersey.
>
> If you guys want, I can post this in the wiki – but somebody
> mentioned that I should first try sending to this email first.
>
>
> Thanks,
>
> Jalpesh
>
>
> PRIVILEGED AND CONFIDENTIAL
> This transmission may contain privileged, proprietary or
> confidential information. If you are not the intended recipient, you
> are instructed not to review this transmission. If you are not the
> intended recipient, please notify the sender that you received this
> message and delete this transmission from your system.