What are Spring's default batch context variables?

In Spring Batch Coverage documentation there are three inexplicable spring context maps: jobParameters , jobExecutionContext and stepExecutionContext .

Springsource sample code combined:

 <bean id="flatFileItemReader" scope="step" class="org.springframework.batch.item.file.FlatFileItemReader"> <property name="var1" value="#{jobParameters['input.file.name']}" /> <property name="var2" value="#{jobExecutionContext['input.file.name']}" /> <property name="var3" value="#{stepExecutionContext['input.file.name']}" /> </bean> 

What are the default options available within jobParameters , jobExecutionContext and stepExecutionContext ?

There are also likely differences between what is available in Spring Batch version 1.x versus 2.x versus 3.x - the documentation in this area is pretty scarce.

+6
source share
3 answers

There are no default values. Think of jobParameters , jobExecutionContext and stepExecutionContext as an illustrious Map using helper methods for different primitive data types, for example. getInt() . They are usually accessed by StepExecution and JobExecution objects passed to *ExecutionListener s, or they are injected using values, for example. @Value("#{jobParameters['foo']}") .

In this case, input.file.name is just the name chosen by the developer, for example. possibly matches the command line job parameter specified in CommandLineJobRunner .

+3
source

#{jobParameters} , #{jobExecutionContext} and #{stepExecutionContext} are the spel (Spring Expression Language) symbol JobParameters , JobExecution and StepExecution objects available in late binding to provide non-static access to these values ​​of objects from the object with steps.

They support access like Map , so you can access the ExecutionContext associated with JobExecution and StepExecution , and the values ​​stored in JobParameters .

Also check out the additional StepScope documentation.

+1
source

See documentation

Parameters JobParameters are parameters that are passed when the job starts.

Execution contexts are intended for your use to store whatever you want. As a rule, the context of the step will contain information that allows you to restart the stage (for restartable tasks).

Elements in the context of the execution of a step can advance to the context of the execution of the task if you want to transfer information between the steps.

0
source

All Articles