I've a job parameter validator where I've mentioned compulsory and optional parameters. I run the batch and it executes correctly.
@Bean
public JobParametersValidator validator() {
String[] compulsoryParameters; //here I've created my compulsory parameters
String[] optionalParams ; //here I've created my optional parameters
return new DefaultJobParametersValidator(compulsoryParameters, optionalParams);
}
Now, If I remove an item from compulsory parameter and if I run it again. It still asks to pass the same parameter.
Caused by: org.springframework.batch.core.JobParametersInvalidException: The JobParameters contains keys that are not explicitly optional or required: [incrementerId]
at org.springframework.batch.core.job.DefaultJobParametersValidator.validate(DefaultJobParametersValidator.java:107)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:126)
Batch Configuration
Compulsory / Optional parameters are configured in application.properties
mybatch.batch.compulsoryParameters=name
mybatch.batch.optionalParameters=inputNumber
@Configuration
@EnableTransactionManagement
@EntityScan(basePackages = "com.something.*")
@EnableJpaRepositories(basePackages = "com.something.*")
@EnableBatchProcessing
@EnableCaching
@EnableConfigurationProperties
@Getter
@Setter
@ConfigurationProperties(prefix = "mybatch.batch", ignoreUnknownFields = false)
public class BatchConfig {
/**
* Configuration settings for the validator
*/
private String[] compulsoryParameters;
private String[] optionalParameters;
/**
* Default validator for Spring Batch
*
* @return
*/
@Bean
public JobParametersValidator validator() {
List<String> tempList = new ArrayList<>();
if (optionalParameters != null) {
Collections.addAll(tempList, optionalParameters);
}
// Adding the run.id parameter for enabling the rerun batches
tempList.add("run.id");
String[] optionalParams = new String[tempList.size()];
optionalParams = tempList.toArray(optionalParams);
return new DefaultJobParametersValidator(compulsoryParameters, optionalParams);
}
}
Note: All the job details are persisting in database.