users@jersey.java.net

Re: [Jersey] _at_Context annotation...

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 22 Jul 2008 11:53:28 +0200

Martin Grotzke wrote:
> Alternatively you can get subresources from jersey using the
> ResourceContext:
>
> @Path("/")
> public static class MyRootResource {
>
> @Context ResourceContext _resourceContext;
>
> @Path( "subresource" )
> public MySubResource getMySubResource() {
> MySubResource result = _resourceContext.getResource( MySubResource.class );
> return result;
> }
>
> }
>
> Then the subresource will get all required fields injected.
>

Plus you can also do following:

     @Path("/")
     public static class MyRootResource {

         @Context ResourceContext _resourceContext;

         @Path( "subresource" )
         public Class<MySubResource> getMySubResource() {
             return MySubResource.class;
         }

     }

that implicitly does what Martin explicitly shows.

Paul.

> Cheers,
> Martin
>
>
>> Here is a (root) resource that uses this technique:
>> http://svn.randompage.org/java/samples/jax-rs/acegi/src/main/java/org/randompage/samples/jaxrs/acegi/resources/UsersResource.java
>>
>> here is the sub resource it uses
>> http://svn.randompage.org/java/samples/jax-rs/acegi/src/main/java/org/randompage/samples/jaxrs/acegi/resources/UserResource.java
>>
>> Hope that helps.
>>
>>
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109