users@jersey.java.net

jsersey 1.1.2 and spring beans defined in xml

From: gabriele renzi <rff.rff_at_gmail.com>
Date: Wed, 21 Oct 2009 14:30:45 +0200

Hi everyone,

sorry if this question is actually answered elsewhere, I spent a few
hours digging into google results spanning the last year and a half,
but in the end I am still unable to reach my goal: expose a bean I
define in spring's XML, using jersey-bundle-1.1.2-ea and
jersey-spring-1.1.2-ea.

Basically I have code like in resources/frontendContext.xml

        <bean id="HttpFacadeBean" class="my.servlet.spring.SpringHttpFacade"
                scope="singleton">
                <constructor-arg ref="aBean" />
                <constructor-arg ref="otherBean" />
                <constructor-arg ref="other" />
...
        </bean>

and the SpringHttpFacade is something like

@Path("/spring")
// @Singleton //I tried with and without this annotation but my I
believe it should not be needed
public class SpringHttpFacade extends AbstractFacade {
        public SpringHttpFacade(Foo foo, Bar bar, Baz baz..) {
                super(foo, bar, baz, ...);
        }
        @Override
        protected something(){.. }
}


according to the docs at
https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/contribs/jersey-spring/com/sun/jersey/spi/spring/container/servlet/SpringServlet.html

this should work with the following web.xml

<web-app>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:resources/frontendContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <display-name>Spring</display-name>
  <servlet>
    <servlet-name>SpringFacade</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>SpringFacade</servlet-name>
    <url-pattern>/spring/*</url-pattern>
  </servlet-mapping>
</web-app>

quoting:
"Any root resource classes or provider classes declared by Spring (in
the XML configuration or by auto-wiring) will be automatically
registered."

I then packaged the war, and dumped the jersey and spring libs in
jetty's shared lib/ directory.

if I start the standalone jetty process with start.jar, though, I do
not get the familiar
"Root resource classes found" message.
and if I try to access the defined urls I get a 503 error.

I tryed tweaking the web.xml config, and adding @Singleton/_at_Component
to my class, but i am unable to workaround this issue, any suggestion
would be greatly appreciated, and excuse me if this was explained
elsewhere.