Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the Spring Batch "default" Context Variables?

In the Spring Batch step-scope documentation, there are three unexplained spring-batch 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 parameters available within jobParameters, jobExecutionContext, and stepExecutionContext?

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

like image 652
JJ Zabkar Avatar asked Mar 05 '14 18:03

JJ Zabkar


2 Answers

There aren't any default values. Think of jobParameters, jobExecutionContext, and stepExecutionContext as glorified Maps with helper methods for different primitive data types, e.g. getInt(). They're typically accessed from the StepExecution and JobExecution objects passed to *ExecutionListeners, or injecting using value injection, e.g. @Value("#{jobParameters['foo']}").

In this case, input.file.name is just a name chosen by the developer, e.g. maybe corresponding to a command line job parameter specified to the CommandLineJobRunner.

like image 59
Emerson Farrugia Avatar answered Sep 19 '22 18:09

Emerson Farrugia


#{jobParameters}, #{jobExecutionContext} and #{stepExecutionContext} are the spEL (Spring Expression Language) counterpart of JobParameters, JobExecution and StepExecution objects available in late-binding to allow non-static access to this objects values from step scoped object.

They support access as Maps so you can access the ExecutionContext associated to JobExecution and StepExecution and values stored in JobParameters.

Also check StepScope documentation for more information.

like image 22
Luca Basso Ricci Avatar answered Sep 17 '22 18:09

Luca Basso Ricci