我有一个工作参数验证器,其中我提到了强制和可选参数。我运行批处理并正确执行。
@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);
}
现在,如果我从强制参数中删除一个项目并再次运行它。它仍然要求传递相同的参数。
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)
批量配置
强制/可选参数在 application.properties 中配置
mybatch.batch.compulsoryParameters=名称
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);
}
}
注意:所有作业详细信息都保存在数据库中。