users@jersey.java.net

[Jersey] jersey-guice inject subresources

From: Christopher Piggott <cpiggott_at_gmail.com>
Date: Wed, 8 Dec 2010 13:02:45 -0500

I've been reading old posts to the mailing list, trying to figure out
if I'm doing this right. I think I am:



import com.google.inject.Inject;

@RequestScoped
@Path("/items")
public class TopResource {
   @GET
   @Path("{itemId}")
   @Inject
   public SubResource getItem(SubResource injectedSub)
   {
      return injectedSub;
   }
}



@RequestScoped
public class SubResource {
   @PathParam("itemId") int itemId;

   @GET
   public String get()
   {
      return "Your item is number " + itemId;
   }
}



I think that should work. I can tell you for sure the following:
  * The TopResource is being created
  * An instance of SubResource is being created through injection
  * in the sub-resource, itemId is 0 ... so that's not working

But the main problem I'm having is:

WARN com.sun.jersey.spi.inject.Errors (173) The following warnings
have been detected with resource and/or provider classes:
  WARNING: A HTTP GET method, public SubResource
TopResource.get(SubResource), should not consume any entity.


I read about a similar problem with "should not consume any entity"
relating to MatrixParam but all I'm trying to do is pass down a path
parameter. Shouldn't that be OK?

--Chris