Spring Batch Commandline Arugments

Spring Batch Commandline Arguments

To use commandline arguments, it’s easy to use org.springframework.batch.core.launch.support.CommandLineJobRunner
About CommandLineJobRunner, I already posted one Spring Batch CommandRunner and XML

Prepare tasklet to use arguments

public class ArgumentTask implements Tasklet {

	private String param1;
	public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
		System.out.println("Argument 1 :" + param1);
		return RepeatStatus.FINISHED;
	 * Required
	 * @param param1
	public void setParam1(String param1) {
		this.param1 = param1;

Setter is required to set parameter

XML to receive

This is batch tasklet configuration(not full)

<batch:job id="argumentjob" job-repository="jobRepository">
        	<batch:step id="task2">
            	<batchlet scope="step"
                	<property name="param1" value="#{jobParameters&#91;'param1'&#93;}"></property>

#{jobParameters[‘param1’] is parameter reference. param1 is key

Run configuration

Add key=value to run(debug) arguments


job.xml argumentjob param1=xxxx