title: How to use Spring Boot 1.5.2 to inject implementations of Jersey endpoint interfaces?
body: <p>I am scaling back a large web application that included a web service to become only a Jersey web service, on Spring Boot 1.5.2.  Because the web service already had a complete set of JAX-RS annotations implemented by Apache Wink, I decided to go with Spring + Jersey instead of Spring Rest.  I found this <a href="https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-jersey" rel="nofollow noreferrer">spring-boot-jersey-sample</a> application to use as a reference.  The biggest difference between the application I'm working on and the sample is that my endpoint definitions are divided between interfaces and implementations.</p>
  
  <p>I added the following to my pom.xml:</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-jersey&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>My new Jersey Config looks like this:</p>
  
  <pre><code>package com.example.configuration;
  
  import org.glassfish.jersey.server.ResourceConfig;
  import com.example.EndpointImpl;
  import org.springframework.stereotype.Component;
  
  @Component
  public class JerseyConfiguration extends ResourceConfig {
    public JerseyConfiguration() {
      registerEndpoints();
    }
  
    private void registerEndpoints() {
      register(EndpointImpl.class);     
    }
  }
  </code></pre>
  
  <p>Then I have the following Application.java:</p>
  
  <pre><code>package com.example;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.boot.builder.SpringApplicationBuilder;
  import org.springframework.boot.web.support.SpringBootServletInitializer;
  
  @SpringBootApplication
  public class Application extends SpringBootServletInitializer{
    public static void main(String[] args) {
      new Application().configure(new SpringApplicationBuilder(Application.class)).run(args);
    }
  }
  </code></pre>
  
  <p>The endpoints are defined as an interface and an implementation, like this (minus imports):</p>
  
  <pre><code>public interface Endpoint {
    @GET
    @Produces({MediaType.APPLICATION_JSON})
    public Response getHello(@Context ServletContext sc, @Context HttpServletRequest req, @Context HttpHeaders httpHeaders) ;
  }
  </code></pre>
  
  
  
  <pre><code>@Path("")
  @Component
  public class EndpointImpl implements Endpoint {
    @Override
    public Response getHello(@Context ServletContext sc, @Context HttpServletRequest req,
        @Context HttpHeaders httpHeaders)  {
        return Response.ok("hello").build();
    }
  }
  </code></pre>
  
  <p>When I start up my application, I see messages saying Tomcat has started up, including a messges saying <code>Mapping servlet: 'com.example.configuration.JerseyConfiguration' to [/*]</code>.  However, when I go to / with a web browser, I get a <code>404 Not Found</code> error.  It doesn't look like the GET definition is getting picked up.  </p>