Spring Boot 3.2.x and Batch - Unable to get value when passing JobParameter value from command line?
I am trying to access JobParameters value in both ways -
- when Passing value in the JobParameters
- when Passing value in the commandLine
Both the approaches are working fine with Spring Boot 2.7.x, but its not working when migrating to Spring Boot 3.2.x. From the Spring Batch Doc, its not clear to me
JobConfig:
@Configuration
public class JobConfiguration {
@Autowired
private JobRepository jobRepository;
@Autowired
private PlatformTransactionManager manager;
@Bean
@StepScope
public Tasklet helloWorldTasklet(@Value("#{jobParameters['message']}") String message,
@Value("#{jobParameters['message1']}") String message1) {
return (stepContribution, chunkContext) -> {
System.out.println(message);
System.out.println(message1);
return RepeatStatus.FINISHED;
};
}
@Bean
public Step step1() {
return new StepBuilder("step1", jobRepository)
.tasklet(helloWorldTasklet(null, null), manager)
.build();
}
@Bean
public Job jobParametersJob() {
return new JobBuilder("jobParametersJob", jobRepository)
.start(step1())
.build();
}
}
Main App.java
@SpringBootApplication
public class JobParametersApplication implements CommandLineRunner{
@Autowired
private JobLauncher jobLauncher;
@Autowired
private Job job;
public static void main(String[] args) {
SpringApplication.run(JobParametersApplication.class, "message1=Aravind Dekate");
}
@Override
public void run(String... args) throws Exception {
JobParameters jobParameters = new JobParametersBuilder()
.addString("message", "MyHello")
.addDate("date", new Date())
.addLong("time",System.currentTimeMillis())
.toJobParameters();
JobExecution execution = jobLauncher.run(job, jobParameters);
System.out.println("STATUS :: "+execution.getStatus());
}
}
I was expecting both the value to be populated.
2025-04-06T00:16:12.815+05:30 INFO 92963 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
MyHello
null