title: Jersey JAX-RS Instance injection
body: <p>I'm trying to inject an instance of a resource into a JAX-RS application with Singleton scope, however when I do this I get:</p>
  
  <blockquote>
    <p>WARNING: A provider com.test.jersey.app.MyResource registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider com.test.jersey.app.MyResource will be ignored. </p>
  </blockquote>
  
  <p>I have an app as follows, that needs an already running instance of MyResource:</p>
  
  <pre><code>public class MyApp extends ResourceConfig {
    public MyApp(MyResource res) {
      super(
          MyService.class
          );
      registerInstances(res);
    }
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>public class MyResource {
    String instanceVar;
  
    public MyResource(String test) {
      instanceVar = test;
    }
  
    public String getString() {
      return instanceVar;
    }
  }
  </code></pre>
  
  <p>With service:</p>
  
  <pre><code>@Path("/service")
  public class MyService {
    @GET
    @Path("")
    public String get(@Context MyResource res) {
      String output;
      if (res != null) {
        output = res.getString();
      } else {
        output = "NOT SET";
      }
      return "output: " + output;
    }
  }
  </code></pre>
  
  <p>This is being run using the following:</p>
  
  <pre><code>public static void main(String[] args) {
    MyResource resource = new MyResource("foo");
    MyApp restApp = new MyApp(resource);
    ServletHolder servlet = new ServletHolder(new ServletContainer(restApp));
    Server jettyServer = new Server(8080);
    ServletContextHandler context = new ServletContextHandler(jettyServer, "/*");
    context.addServlet(servlet, "/*");
    try {
      jettyServer.start();
      jettyServer.join();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      jettyServer.destroy();
    }
  }
  </code></pre>
  
  <p>I tried using an AbstractBinder, but couldn't find a way to bind the <strong>instance</strong> of MyResource to the service.</p>
  
  <p>Dependencies:</p>
  
  <pre><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
          &lt;version&gt;2.23.2&lt;/version&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-container-servlet-core&lt;/artifactId&gt;
          &lt;version&gt;2.23.2&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-container-jetty-http&lt;/artifactId&gt;
          &lt;version&gt;2.23.2&lt;/version&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-media-json-jackson&lt;/artifactId&gt;
          &lt;version&gt;2.23.2&lt;/version&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
          &lt;artifactId&gt;jetty-servlet&lt;/artifactId&gt;
          &lt;version&gt;9.2.19.v20160908&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
          &lt;artifactId&gt;jetty-util&lt;/artifactId&gt;
          &lt;version&gt;9.2.19.v20160908&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
          &lt;artifactId&gt;jetty-server&lt;/artifactId&gt;
          &lt;version&gt;9.2.19.v20160908&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
          &lt;artifactId&gt;jetty-jmx&lt;/artifactId&gt;
          &lt;version&gt;9.2.19.v20160908&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
          &lt;artifactId&gt;javax.ws.rs-api&lt;/artifactId&gt;
          &lt;version&gt;2.0&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>