users@jersey.java.net

[Jersey] Re: _at_Context/_at_Inject not working on interfaces

From: Trenton D. Adams <trenton.d.adams_at_gmail.com>
Date: Fri, 10 Jun 2016 12:12:11 -0600

Okay, thanks.

On Fri, Jun 10, 2016 at 4:12 AM, Robert Gacki <robert.gacki_at_contenttrace.org
> wrote:

> Hi,
>
> the @Inject / @Context annotations are an implementation detail and
> should not be used to annotate interfaces. So don't expect Jersey to
> traverse into the class hierarchy to collect those annotations.
>
> Robert
>
> Am Freitag, den 10.06.2016, 01:35 -0600 schrieb Trenton D. Adams:
> > I noticed that @Context and @Inject do not work on interfaces. Is
> > that intentional? It works perfectly if I put the annotations on the
> > member variables themselves.
> >
> > I define this on my interface, and it does not get called on the
> > implementing class.
> >
> > On the interface I have...
> > void setServiceUri(@Context UriInfo serviceUri);
> >
> > void setRequest(@Context HttpServletRequest request);
> >
> > @Inject
> > void setSession(HttpSession session);
> >
> > On the implementing class I have...
> > @Override
> > public void setServiceUri(UriInfo serviceUri)
> > {
> > this.serviceUri = serviceUri;
> > }
> >
> > @Override
> > public void setRequest(HttpServletRequest request)
> > {
> > this.request = request;
> > }
> >
> > @Override
> > public void setSession(HttpSession session)
> > {
> > this.session = session;
> > }
> >
> > I set a break point on any of the set methods, and none of them gets
> > called.
>