title: Using a job parameter as a prepared statement parameter in a JdbcCursorItemReader
body: <p>I have a job that has to run multiple times with different job parameters. I want to set up a JdbcCursorItemReader to perform a query for the job, the itemReader is configured like this:</p>
  
  <pre><code>&lt;bean id="tpsItemReader" 
      class="org.springframework.batch.item.database.JdbcCursorItemReader"&gt;
      &lt;property name="dataSource" ref="myDataSource"/&gt;
      &lt;property name="sql" value="#{sqlQueries['tps.findStuffforSomeSubset']}"/&gt;
      &lt;property name="preparedStatementSetter"&gt;
          &lt;bean class="com.initech.reports.tps.ParameterSetter"&gt;
              &lt;!-- can't hardcode this, I want a job parameter here --&gt;
              &lt;constructor-arg value="A"/&gt; 
          &lt;/bean&gt;
      &lt;/property&gt;
      &lt;property name="rowMapper"&gt;
          &lt;bean class="com.initech.reports.tps.CustomerRowMapper"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>and the job is configured like this:</p>
  
  <pre><code>&lt;batch:job id="tpsReportJob"&gt;
      &lt;batch:step id="tpsReportJob.generateReport"&gt;
          &lt;batch:tasklet&gt;
              &lt;batch:chunk reader="tpsItemReader" 
              processor="tpsItemProcessor" 
              writer="tpsItemWriter" commit-interval="100000"/&gt;
          &lt;/batch:tasklet&gt;
      &lt;/batch:step&gt;
  &lt;/batch:job&gt;
  </code></pre>
  
  <p>The parameterSetter is pretty minimal:</p>
  
  <pre><code>package com.initech.reports.tps;
  
  import java.sql.PreparedStatement;
  import java.sql.SQLException;
  
  import org.springframework.jdbc.core.PreparedStatementSetter;
  
  public class ParameterSetter implements PreparedStatementSetter {
  
      private final String x;
  
      public ParameterSetter(String x) {this.x = x;}
  
      @Override
      public void setValues(PreparedStatement ps) throws SQLException {
          ps.setString(1, x);
      }
  }
  </code></pre>
  
  <p>This is using spring-batch 2.1.8.</p>
  
  <p>How do I get the job parameter into the query?</p>
  
  <p>I think I'm close, I tried changing the parameter setter config to:</p>
  
  <pre><code>        &lt;bean class="com.initech.reports.tps.ParameterSetter"&gt;
              &lt;constructor-arg value="#{jobParameters['myParam']}"/&gt;
          &lt;/bean&gt;
  </code></pre>
  
  <p>but I get this error:</p>
  
  <pre><code>Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
      at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:208)
      at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:72)
      at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:52)
      at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:93)
      at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:88)
      at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:139)
      ... 51 more
  </code></pre>
  
  <p>I found <a href="https://stackoverflow.com/q/6078009/217324">a very similar question</a>, the difference between that one and this is that I don't have a reader class to annotate, I just have the xml entry because I'd like to avoid having to create my own itemReader. (I could try overriding the jdbcCursorItemReader class just to be able to annotate it...)</p>