[Jersey] Spring's _at_Autowired field not being set within root resource class

From: Farrukh Najmi <>
Date: Wed, 28 Sep 2011 21:47:33 -0400

I have a top level resource class MyResource in my jersey server that is
correctly being invoked by a jersey client from my junit test.

The junit test starts MyResource in a
org.glassfish.grizzly.http.server.HttpServer, using a
com.sun.jersey.spi.container.servlet.ServletContainer and a
org.glassfish.grizzly.servlet.ServletHandler to set the servlet context,
context-params and init-params.

I then added spring integration to my server using the following blog as
a guide:

Since I do not have an actual servlet but instead have
org.glassfish.grizzly.servlet.ServletHandler I adapted my ServletHandler
as follows:

     public void startServer() {

         // add Jersey resource servlet

         ServletHandler jerseyAdapter = new ServletHandler();

         //Context params

         //Init params

         jerseyAdapter.setServletInstance(new ServletContainer());

         //Servlet listeners

         try {

             webServer = GrizzlyServerFactory.createHttpServer(

         } catch (Exception ex) {

So far all is well and I can see that my spring ApplicationContext is
created and the beans defined within are instantiated (good).

Next, I added a field to MyResource where

    * Class is annotated by @Component and @Scope
    * Field foo is annotated with @Autowired

public class MyResource {
     private Foo foo;

     public Response allEventsGet() {
*... field foo is null here and autowiring does not seem to be working
(not good) ....*

     public void setFoo(Foo foo) { = foo;

Can any one tell me what I am doing wrong that is causing the field foo
to not be auto-wired in MyResource? Looking at the TRACE messages from
spring I can see that the singleton Foo instance was indeed created.
However it never gets injected into the @Autorwired field foo in MyResource.

Thanks for your help.

Farrukh Najmi