gpt4 book ai didi

即使我更改了作业参数验证器,Spring 批处理作业参数也不会被覆盖

转载 作者:行者123 更新时间:2023-12-05 08:11:26 24 4
gpt4 key购买 nike

我有一个作业参数验证器,我在其中提到了强制参数和可选参数。我运行批处理,它正确执行。

@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=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);
}


}

注意:所有工作细节都保存在数据库中。

最佳答案

由于错误说明清楚,每个参数都必须是 compulsoryParametersoptionalParams 的一部分。

例如,对于我的工作,传递三个参数 START_DATE、RUN_DATE 和 END_DATE。我已将所有内容包含在 compulsoryParameters 中,如果我从此列表中删除一个并继续传递,则它会出错,说参数中有一个键未明确添加到任一列表中。

@Bean
public JobParametersValidator validator() {
String[] compulsoryParameters = {"START_DATE", "RUN_DATE", "END_DATE"}; //here I've created my compulsory parameters
String[] optionalParams = {""}; //here I've created my optional parameters

return new DefaultJobParametersValidator(compulsoryParameters, optionalParams);
}

因此,尝试通过添加到 compulsoryParametersoptionalParams 来添加所有传递的参数。这应该可以解决问题。

关于即使我更改了作业参数验证器,Spring 批处理作业参数也不会被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57311698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com