title: Could not autowired Object in ItemStreamReader open method
body: <p>I use Spring Batch with Spring Boot and here is a my main class.</p>
  
  <pre><code>@SpringBootApplication
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>Here is my configuration classes</p>
  
  <pre><code>@Configuration
  public class AppConfig {
  
      @Bean
      public MyObject getObject() {
          return new MyObject();
      }
  }
  
  @Configuration
  @EnableBatchProcessing
  public class BatchConfiguration {
  
      private static final String OVERRIDDEN_BY_EXPRESSION = null;
  
      @Autowired
      private JobBuilderFactory jobs;
  
      @Autowired
      private StepBuilderFactory steps;
  
      @Bean
      public Job job() {
          return jobs.get(Constants.FULL_JOB_NAME)
                  .start(stepProcessDocument())
                  .build();
      }
  
      @Bean
      protected Step stepProcessDocument() {
          return steps.get(Constants.STEP_PROCESS_DOCUMENT_NAME)
              .&lt;Document,Document&gt;chunk(10)
              .reader(buildItemReader(OVERRIDDEN_BY_EXPRESSION))
              .processor(buildItemProcessor())
              .writer(buildItemWriter(OVERRIDDEN_BY_EXPRESSION))
              .build();
      }
  
      @Bean
      @StepScope
      protected ItemReader&lt;Document&gt; buildItemReader(@Value("#{jobParameters[" + Constants.PARAM_JOB_PARAMETER + "]}") String param) {
          ItemStreamReader&lt;Document&gt; reader = new CustomItemReader(param);
          reader.open(new ExecutionContext());
          return reader;
      }
  
      @Bean
      protected ItemProcessor&lt;Document, Document&gt; buildItemProcessor() {
          return new CustomItemProcessor();
      }
  
      @Bean
      @StepScope
      protected ItemWriter&lt;Document&gt; buildItemWriter(@Value("#{jobParameters[" + Constants.PARAM_JOB_PARAMETER + "]}") String param) { 
          ItemStreamWriter&lt;Document&gt; writer = new CustomItemWriter(param);
          writer.open(new ExecutionContext());
          return writer;
      }
  
      @Bean
      public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor(JobRegistry jobRegistry) {
          JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor = new JobRegistryBeanPostProcessor();
          jobRegistryBeanPostProcessor.setJobRegistry(jobRegistry);
          return jobRegistryBeanPostProcessor;
      }
  }
  </code></pre>
  
  <p>Here is a custom file reader I use in my application.</p>
  
  <pre><code>public class CustomItemReader implements ItemStreamReader&lt;Document&gt; {
  
  @Autowired
  private MyObject myObject;
  
  private int count = 0;
  private String param;
  
  public CustomItemReader(String param) {
      this.param = param;
  }
  
  @Override
  public void open(ExecutionContext executionContext)
          throws ItemStreamException {
      myObject.open(); //myObject is null
  }
  
  @Override
  public void update(ExecutionContext executionContext)
          throws ItemStreamException {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void close() throws ItemStreamException {
      myObject.close();
  }
  
  @Override
  public Document read() throws Exception, UnexpectedInputException,
          ParseException, NonTransientResourceException {
      myObject.doStuff();
      count++;
      if(count == 5) {
          return null;
      }
      return new Document();
  }
  </code></pre>
  
  <p>I got a Java null pointer exception on myObject.
  Why I could not autowired java object in the ItemStreamReader open method?</p>