Old question, but still applies to current version (3.0.5):
If you are starting the job execution via
JobExecution jobExecution = launcher.run(job, jobParameters);
using e.g. the SimpleJobLauncher
class, then the incrementer is never called. If you check the "callers" of the method Incrementer.getNext(JobParameters)
, the number of callers is limited:
- org.springframework.batch.core.launch.support.CommandLineJobRunner
CommandLineJobRunner does the call to getNext()
conditionally on "-next" before calling the launcher:
if (opts.contains("-next")) {
JobParameters nextParameters = getNextJobParameters(job);
Map<String, JobParameter> map = new HashMap<String, JobParameter>(nextParameters.getParameters());
map.putAll(jobParameters.getParameters());
jobParameters = new JobParameters(map);
}
JobExecution jobExecution = launcher.run(job, jobParameters);
- org.springframework.batch.core.launch.support.SimpleJobOperator
This is used by the Spring Admin web application and it is basically the same implementation as in CommandLineJobRunner:
if (lastInstances.isEmpty()) {
parameters = incrementer.getNext(new JobParameters());
if (parameters == null) {
throw new JobParametersNotFoundException("No bootstrap parameters found for job=" + jobName);
}
}
else {
List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
parameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
}
logger.info(String.format("Attempting to launch job with name=%s and parameters=%s", jobName, parameters));
try {
return jobLauncher.run(job, parameters).getId();
}
catch (JobExecutionAlreadyRunningException e) {
throw new UnexpectedJobExecutionException(String.format(ILLEGAL_STATE_MSG, "job already running", jobName,
parameters), e);
}
So if you are using using the JobLauncher class for starting Jobs, must must take care of yourself for calling the incrementer before calling the jobLauncher to enhance the job parameter with your desired values.