title: Spring autowiring parameterized generic types
body: <p>Spring 4 included major enhancements to generic type resolution, but I'm having trouble with autowiring a generic type when the type argument is parameterized on the containing bean class.</p>
  
  <p>I am needing to track the status of jobs submitted to an outside service, and I want to create an entry for each job when it starts and clear or update it when I receive postbacks. I generally try to keep my persistence strategy separated from the service interface, so I have an interface <code>JobStatus</code> and a Spring Data Mongo class <code>MongoJobStatus implements JobStatus</code>. Since a job might fail before the outside service gets a chance to assign it an ID (e.g., an HTTP 502), I need to pass the <code>JobStatus</code> back to the service to identify for updates:</p>
  
  <pre><code>interface JobStatusService&lt;S extends JobStatus&gt; {
      S beginJob(...);
      S updateJobStatus(S targetJob, Status newStatus);
      void finishJob(S targetJob);
  }
  </code></pre>
  
  <p>Accordingly, my Spring controller that handles firing off the jobs and recording the postbacks looks like this; the controller class carries a type parameter so that I can store the new status object and pass it back to the service:</p>
  
  <pre><code>@Controller
  public class JobController&lt;JS extends JobStatus&gt; {
      @Autowired JobStatusService&lt;JS&gt; jobService;
  
      ... handler method ...
      JS status = jobService.createJob(info, goes, here);
      // submit job via HTTP
      jobService.updateJobStatus(status, Status.PROCESSING);
      ...
  }
  </code></pre>
  
  <p>My MongoDB-backed implementation looks like this:</p>
  
  <pre><code>public class MongoJobStatusService implements JobStatusService&lt;MongoJobStatus&gt; {
      MongoJobStatus beginJob(...) {...}
      MongoJobStatus updateJobStatus(MongoJobStatus job, Status newStatus) {...}
  }
  </code></pre>
  
  <p>When I try to launch, the Spring context fails with <code>NoSuchBeanDefinitionException</code> for <code>JobStatusService</code>. I have confirmed that if I set <code>required=false</code>, the <code>MongoJobStatusService</code> bean is properly component-scanned and installed in the context, but Spring doesn't seem to be able to understand that the class implements that parameterized generic interface.</p>
  
  <p>Is there any way to specify to Spring that I need a bean implementing a generic interface with a type argument that is parameterized at the containing bean level instead of embedded as a literal type argument on the field level?</p>