users@jersey.java.net

[Jersey] Re: Debugging _at_Context injection failure on Tomcat

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 03 Nov 2011 18:45:32 +0100

Hi,

On 2.11.2011 23:16, nbeyer_at_cerner.com wrote:
> I'm using jersey 1.9.1 and getting some dependency injection failures
> on the loading of resources via @Context. I've seen then when using
> Grizzly in a unit test scenario, but I'm also experiencing it when
If that was a non-Servlet Grizzly container, then you can not expect the
ServletContext
injectable provider being used there.

> deploying to Tomcat 6.0.x. The confusing part is I have the exact same
> resource with the same @Context ServletContext injection in two
> different projects and one project loads fine and functions correctly,
> but the other project fails to load.

The only thing which i can think of at the moment would be some strange
class-loading issue.
Could you maybe check out, you do not bundle any jar containing
javax.servlet package with your application?

~Jakub

P.S. In a Servlet container, the WebComponent (see line 562 of [1])
class is responsible for adding
an InjectableProvider for the ServletContext. I presume the provider is
added all right.

[1]http://java.net/projects/jersey/sources/svn/content/trunk/jersey/jersey-servlet/src/main/java/com/sun/jersey/spi/container/servlet/WebComponent.java?rev=5478

> Here's what the resource method looks like in both projects -
>
> @GET
> @Produces(MediaType.TEXT_HTML)
> public Response get(@Context ServletContext context) {
> # ...
> }
>
> Here's the error reported when the resource is hit via a browser -
> SEVERE: The following errors and warnings have been detected with
> resource and/or provider classes:
> SEVERE: Missing dependency for method public
> com.blah.resources.BlahResource.get(javax.servlet.SerlvetContext) at
> parameter index 0
>
> Any suggestions on how to debug this and find the difference between
> the two projects?
>