title: Proper way to write a spring-batch ItemReader
body: <p>I'm constructing a spring-batch job that modifies a given number of records. The list of record ID's are an input parameter of the job. For example, one job might be: Modify the record Id's {1,2,3,4} and set parameters X and Y on related tables.</p>
  
  <p>Since I'm unable to pass a potentialy very long input list (tipical cases, 50K records) to my ItemReader I only pass a MyJobID which then the itemReader uses to load the target ID list.</p>
  
  <p>Problem is, the resulting code appears "wrong" (altough it works) and not in the spirit of spring-batch. Here's the reader:</p>
  
  <pre><code>@Scope(value = "step", proxyMode = ScopedProxyMode.INTERFACES)
  @Component
  public class MyItemReader implements ItemReader&lt;Integer&gt; {
  
      @Autowired
      private JobService jobService;
      private List&lt;Integer&gt; itemsList;
      private Long jobId;
  
      @Autowired
      public MyItemReader(@Value("#{jobParameters['jobId']}") final Long jobId) {
          this.jobId = jobId;
          this.itemsList = null;
      }
  
      @Override
      public Integer read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
  
          // First pass: Load the list.
          if (itemsList == null) {
              itemsList = new ArrayList&lt;Integer&gt;();
  
              MyJob myJob = (MyJob) jobService.loadById(jobId);
  
              for (Integer i : myJob.getTargedIdList()) {
                  itemsList.add(i);
              }
          }
  
          // Serve one at a time:
          if (itemsList.isEmpty()) {
              return null;
          } else {
              return itemsList.remove(0);
          }
      }   
  }
  </code></pre>
  
  <p>I tried to move the first part of the read() method to the constructor but the @Autowired reference is null at that point. Afterwards (on the read method) it's initialized.</p>
  
  <p>Is there a better way to write the ItemReader? I would like to move the "load"Or is this the best solution for this scenario?</p>
  
  <p>Thank you.</p>