users@jersey.java.net

injecting ResourceContext into a spring request scoped bean

From: Tim Wood <T.Wood_at_Resilientplc.com>
Date: Tue, 23 Nov 2010 17:20:45 -0000

Hi,

I am having trouble understanding how to inject the ResourceContext into
a bean that was created by spring. For example, I have two classes. A
sub-resource managed by Jersey and a plain request scoped bean managed
by spring.

@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class SomeResource
{
   @Inject
   Private MyBean myBean;

   [...]
}

@Component
@Scope("request")
public class MyBean implements IMyBean
{
   @Context
   private ResourceContext resourceContext;

   [...]
}


I was expecting the member variable resourceContext to be set with the
correct ResourceContext. However, it is never injected (always null).
myBean is injected and any spring auto-wired members in it are filled
in; but the jersey annotated resourceContext member is not.

I thought that Jersey (1.3) would fill in the @Context and @Inject and
@PathParam, etc, annotations when satisfying the @Inject. Have I
misunderstood how this is supposed to work? What is the best way to do
something like this?

Cheers,

Tim