title: JobParameters from Spring Batch
body: <p>I am trying to inject job parameters into a custom ItemReader.  I have reviewed all of the StackOverflow notes on the subject (example: <a href="https://stackoverflow.com/questions/6078009/how-to-get-access-to-job-parameters-from-itemreader-in-spring-batch">How to get access to job parameters from ItemReader, in Spring Batch?</a>), and I see this is a common pain point that is mostly unresolved.  I am hoping that a spring guru (@Michael Minella anyone) will see this and have some insight.</p>
  
  <p>I have got as far as determining that the jobparameters are available about one out of 10 runs, even with no code or configuration changes.  This is a case of a random success rather than a random failure, so it's proving hard to track down.</p>
  
  <p>I dug into the spring code with the debugger, and determined that when this fails, no bean of the name jobParameters is registered in Spring at the time that the injection is taking place.  </p>
  
  <p>I am using Spring 4.1.4 with spring-batch 3.0.2 and spring-data-jpa 1.7.1 and spring-data-commons 1.9.1, running in java 8.</p>
  
  <p>Java class</p>
  
  <pre><code>@Component("sourceSelectionReader")
  @Scope("step")
  public class SourceSelectionReaderImpl  
  implements ItemReader&lt;MyThing&gt; {
      private Map&lt;String,Object&gt; jobParameters;
  
  // ... snip ...
  
  
      @Autowired
      @Lazy
      @Qualifier(value="#{jobParameters}")
      public void setJobParameters(Map&lt;String, Object&gt; jobParameters) {
          this.jobParameters = jobParameters;
      }
  }
  </code></pre>
  
  <p>Job launch parameters:</p>
  
  <pre><code>launch-context.xml job1 jobid(long)=1
  </code></pre>
  
  <p>launch-context.xml (minus the fluff):</p>
  
  <pre><code>&lt;context:property-placeholder location="classpath:batch.properties" /&gt;
  
  &lt;context:component-scan base-package="com.maxis.maximo.ilm" /&gt;
  
  &lt;jdbc:initialize-database data-source="myDataSource"  enabled="false"&gt;
      &lt;jdbc:script location="${batch.schema.script}" /&gt;
  &lt;/jdbc:initialize-database&gt;
  
  &lt;batch:job-repository id="jobRepository" 
      data-source="myDataSource"
      transaction-manager="transactionManager"
      isolation-level-for-create="DEFAULT"
      max-varchar-length="1000"/&gt;
  
  &lt;import resource="classpath:/META-INF/spring/module-context.xml" /&gt;
  </code></pre>
  
  <p>Module-context.xml (minus the fluff):</p>
  
  <pre><code>&lt;description&gt;Example job to get you started. It provides a skeleton for a typical batch application.&lt;/description&gt;
  
  &lt;import resource="classpath:/META-INF/spring/hibernate-context.xml"/&gt;
  &lt;import resource="classpath:/META-INF/spring/myapp-context.xml"/&gt;
  
  &lt;context:component-scan base-package="com.me" /&gt;
  &lt;bean class="org.springframework.batch.core.scope.StepScope" /&gt;
  
  &lt;batch:job id="job1"&gt;
      &lt;batch:step id="step0002"  &gt;            
          &lt;batch:tasklet transaction-manager="transactionManager" start-limit="100" &gt;
              &lt;batch:chunk reader="sourceSelectionReader" writer="selectedDataWriter" commit-interval="1" /&gt;
          &lt;/batch:tasklet&gt;
      &lt;/batch:step&gt;
  &lt;/batch:job&gt; 
  </code></pre>