jobParameters cannot be found on object of type BeanExpressionContext

Create a simple Spring batch job to write data to a csv file. The csv file name depends on the pass in job’s parameters, interprets by Spring EL .

<bean id="csvFileItemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
  <!-- write to this csv file -->
  <property name="resource" 
      value="file:outputs/csv/domain.done.#{jobParameters['pid']}.csv" />
  <property name="appendAllowed" value="false" />
  <property name="lineAggregator">
	<property name="delimiter" value="," />
	<property name="fieldExtractor">
	    <bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
		<property name="names" value="id, domainName" />

Unit test above job :

public class TestSampleJob extends AbstractTestNGSpringContextTests {
    private JobLauncherTestUtils jobLauncherTestUtils;
    public void launchJob() throws Exception {
    	JobParameters jobParameters = 
    	    new JobParametersBuilder().addString("pid", "10").toJobParameters();
        JobExecution jobExecution = jobLauncherTestUtils.launchJob(jobParameters);
        Assert.assertEquals(jobExecution.getStatus(), BatchStatus.COMPLETED);


It prompts “jobParameters cannot be found” error message :

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(
	at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(
	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(


The jobParameters bean can not actually be instantiated until the “Step” starts. To fix it, late binding with a scope of “Step” is required.

  <bean id="csvFileItemWriter" 
	class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
	<!-- ...... -->


  1. Spring Batch – Step Scope
Tags :

About the Author

Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.