users@jersey.java.net

[Jersey] Re: Annotating Interfaces

From: Arul Dhesiaseelan <aruld_at_acm.org>
Date: Tue, 1 May 2012 15:41:16 -1000

You may want to check this section on Annotation inheritance:
http://jsr311.java.net/nonav/releases/1.1/spec/spec3.html#x3-330003.6

The JAX-RS inheritance rules do provide a mechanism for overriding
inherited annotations. However, it is not possible to completely remove
JAX-RS annotations from a construct that inherits them from a super class
or interface (
http://fusesource.com/docs/esb/4.2/rest/RESTAnnotateInherit.html).

Essentially, you need to move your @Path marker from your interface to your
resource class. So, this should work just fine for you.

public interface BlahResource {
  @Path("/blah/{id}")
  @GET
  public String getTheBlah(@PathParam("id") int id);
}

@Path("/") --> This qualifies when scanning a resource from
classpath/package.
public class JaxRsBlahResource implements BlahResource {
  public String getTheBlah(int id) {
    System.out.println("Blah! " + id);
    return "Blah!";
  }
}

Hope this helps!

-Arul

On Mon, Apr 30, 2012 at 11:32 PM, Colin Vipurs <zodiaczx6_at_gmail.com> wrote:

> I have a project that uses Spring that I wish to introduce AOP to.
> Our resource classes have constructors with arguments so I believe
> this requires introducing interfaces and annotating those instead of
> the implementation so that Spring can do its "magic", and this is
> where the problems start.
>
> I've moved my annotations to my interface, so I end with something like:
>
> @Path("/")
> public interface BlahResource {
> @Path("/blah/{id}")
> public void getTheBlah();
> }
>
> public class JaxRsBlahResource implements BlahResource {
> public void getTheBlah() { .... }
> }
>
> This throwns an error as following:
>
> SEVERE: Conflicting URI templates. The URI template / for root
> resource class JaxRsBlahResource and the URI template / transform to
> the same regular expression (/.*)?
>
> So it seems that the @Path component is being picked up twice. If I
> add another @Path annotation to the implementation, so something like:
>
> @Path("/blah")
>
> The everything works ok, but I now have that resource exposed at two
> different endpoints.
>
> It feels like I'm missing something obvious, but I'm tearing my hair
> out figuring out what?
>
> --
> Maybe she awoke to see the roommate's boyfriend swinging from the
> chandelier wearing a boar's head.
>
> Something which you, I, and everyone else would call "Tuesday", of course.
>



-- 
http://aruld.info
http://twitter.com/aruld