title: Autowired Repository null in Controller for a Spring Boot application
body: <p>I am writing a Spring Boot application with a REST service based on jersey. </p>
  
  <p>My repository interface is as below </p>
  
  <pre><code>@Repository
  public interface ConnectionRepository extends CrudRepository&lt;Connection, Integer&gt;
  {
  
  
  }
  </code></pre>
  
  <p>My REST service is as follows </p>
  
  <pre><code>@Component
  @Path("/conn")
  public class ConnectionService
  {
      @Autowired
      private ConnectionRepository cer;
  
      @GET
      @Path("/{id}/")
      @Produces(MediaType.APPLICATION_JSON)
      public Response getSpConnection(@PathParam("id") String tid) throws Exception
      {
          Gson gson = new Gson();
  
          if(cer == null)
          {
              return Response.status(Response.Status.OK).entity("Hello World").build();
          }
          Connection conendpoint = cer.find(tid);
          if(conendpoint == null)
          {
              return Response.status(Response.Status.NOT_FOUND).build();
          }
          else
          {
              String jsonConn = gson.toJson(conendpoint);
              return Response.status(Response.Status.OK).entity(jsonConn).build();
          }
  
      }
  } 
  </code></pre>
  
  <p>Application.java </p>
  
  <pre><code>@EnableAutoConfiguration
  @SpringBootApplication
  @ComponentScan
  @Component
  @PropertySource("classpath:/application.properties")
  @Import(PersistenceContext.class)
  public class Application extends SpringBootServletInitializer
  {
  
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(applicationClass);
      }
  
      private static Class&lt;Application&gt; applicationClass = Application.class;
  
      public static void main(String[] args)
      {
          SpringApplication.run(Application.class, args);
      }
  
  }
  </code></pre>
  
  <p>PersistenceContext contains information for datasource and other beans.</p>
  
  <p>Whenever I access this REST service, I get ConnectionRepository as null and the response is "Hello World". I am using <code>spring-boot-starter-web</code>,<code>spring-boot-starter-jersey</code> and <code>spring-boot-starter-data-jpa</code>.</p>
  
  <p>What am I missing? </p>