In this recipe, you'll learn how to retrieve and use a job parameter value in Tasklet
.
Follow these steps to use the job parameters:
In the
Task1
class, add@StepScope
to theexecute()
method:@StepScope public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { ...
In the
execute()
method, retrieve a job parameter value by using the job parameter name:String test = (String)chunkContext.getStepContext().getJobParameters(). get("test")
Run the job with a parameter named
test
:mvn compile exec:java - Dexec.mainClass=org.springframework.batch.core.launch. support.CommandLineJobRunner - Dexec.args="com.spring_cookbook.batch.BatchConfig job1 test=hello"