On 15 Mar 2014, at 10:48 PM, Guy Rouillier <guy.rouillier_at_gmail.com> wrote:
> This actually works out okay. We start by implementing the resource class, with a complete set of annotations. When we are done, we then (from within Eclipse) use refactor to extract the interface. When doing so, refactor includes all the annotations from the implementing class *except* for the annotations on the class itself (for us, usually just @Path and @Singleton.) So, we have to remember to copy those manually. Would be better, obviously, if Eclipse also generated the class level annotations, but oh well...
>
> I believe you that having done this, Jersey will then ignore all the annotations on the interface, because the implementing class has its own annotations. But it doesn't matter, because the interface and the implementing class have the exact same set of annotations. The interface is for use by the client proxy, and the implementing class is for use by Jersey on the server.
>
> To answer Graham, this arrangement works for us. We have over a dozen resources implemented with this approach.
After much digging what I found that eventually worked was to use the annotations on the interfaces, the implementation in the implementation class, and use an Application object to set the application us, like this:
public class Application extends javax.ws.rs.core.Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> implementations = new HashSet<Class<?>>();
/* explicitly add implementation class */
implementations.add(UserResourceImpl.class);
implementations.add(RoleResourceImpl.class);
implementations.add(GroupResourceImpl.class);
return implementations;
}
}
The package scanner seems to be broken in that it cannot detect objects that inherit from interfaces, so the workaround is programmatically add the implementations.
Regards,
Graham
--