From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Fri, 11 Mar 2011 17:01:42 +0100
On 03/11/2011 04:40 PM, Martynas Jusevicius wrote:
> It seems that only the root resource gets context initialized, not the
> subresource - even though they extend the same superclass which holds
> the injected field, so I would expect the same behaviour. And I mean
> request methods here, not constructors. The output:
>
> Resource: RootResource_at_fdde57 Method: @GET ServletContext:
> org.apache.catalina.core.ApplicationContextFacade_at_12cb562
> Resource: SubResource_at_150d191 Method: @GET ServletContext: null
>
> What am I missing again? Is it the same issue as here:
> http://jersey.576304.n2.nabble.com/Instatiating-subResources-with-Context-class-fields-td5360153.html >
> Thanks again,
>
> Martynas
Yes, it's basically the same issue.
If you are directly intantiating the subresource using new SubResource() the subresource fields don't get injected. In
Jersey you can use ResourceContext.getResource(SubResource.class)[1] instead of direct constructor. That way the
subresource should get injected too.