How to annotate JAX-RS on an interface while using Jersey
<p>This question had been asked a few times <a href="https://stackoverflow.com/questions/20148269/restful-service-interface-with-jersey">before</a>, however the answers doesn't seem to work and/or Jersey has moved on with more changes.</p>

<p>I'm exposing some REST APIs using JAX-RS and Jersey (version 2.24). And I wish to annotate the interface with JAX-RS and a concrete implementation (without any annotations). However, since <a href="https://java.net/jira/browse/JERSEY-1004?focusedCommentId=347987&amp;page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-347987" rel="noreferrer">this patch</a> Jersey stopped supporting this possibility. As far as I understand the <a href="https://jcp.org/en/jsr/detail?id=339" rel="noreferrer">spec</a>, it doesn't strictly prohibit doing that.</p>

<blockquote>
  <p>If a subclass or <strong>implementation method</strong> has any JAX-RS annotations then all of the annotations on the superclass or interface method are ignored.</p>
</blockquote>

<p>implying that it is totally okay to do that. In many cases it is good to use an interface, and have a server and client each have their respective implementations.</p>

<p>There are plenty of solutions out there, </p>

<ol>
<li>Use a <code>ResourceConfig</code> and do a <code>registerClasses(MyImplementation.class)</code> . However, this doesn't work.</li>
<li>Disable the package scanning configuration in <code>web.xml</code>, create a custom <code>javax.ws.rs.Application</code> and do a <code>register</code> of your implementation from there. Doesn't work.</li>
<li>use a <code>ResourceConfig</code> and define a custom <code>AbstractBinder</code> and do a <code>bind</code> so that Jersey's dependency injection can find the concrete implementations. Doesn't work.</li>
<li>Use RESTEasy. RESTEasy doesn't seem to impose the interface restrictions as in Jersey. Never tried it myself.</li>
</ol>

<p>I would appreciate if someone can share their experience with this. Any help on how to get Jersey working would be great too. As for the option (4) is it really necessary to switch ? A sample code below. </p>

<p><code>MyResource</code></p>

<pre class="lang-java prettyprint-override"><code> package com.foo;

import javax.ws.rs.GET;
import javax.ws.rs.Path;


@Path("/hello")
public interface MyResource {

  @GET
  public String sayHello();

}
</code></pre>

<p><code>MyResourceImpl</code></p>

<pre><code>package com.bar;

public class MyResourceImpl implements MyResource {

  @Override
  public String sayHello() {
    return "Hello Jersey";
  }
}
</code></pre>

<p>Also have a <code>web.xml</code> that has the package scanning enabled to scan <code>com.foo</code></p>