我目前在Spring Cloud Data Flow中遇到了我的任务调用问题。
我有一个在SCDF上注册的Spring Batch(包含单任务程序步骤作业)应用程序和基于此应用程序的任务定义。在我第一次启动此任务时,我使用了几个作业参数/参数。由于我现在知道的原因,我后来的所有启动都是通过我使用的第一组来覆盖它们的参数。
我正在使用SCDF 1.4.0 + MSSQL数据库,但使用SCDF 1.3.2 + H2或MSSQL也会发生同样的行为。
BatchConfig.java
@Configuration
public class BatchConfig {
@Autowired
TaskletStep taskletStep;
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Bean
public Step step1() {
return stepBuilderFactory.get("step1")
.tasklet(taskletStep)
.build();
}
@Bean
public Job job() throws Exception {
return jobBuilderFactory.get("job")
.incrementer(new RunIdIncrementer())
.start(step1())
.build();
}
}
TaskletStep.java:
@Configuration
@StepScope
public class TaskletStep implements Tasklet{
@Value("#{jobParameters['filePath']}")
private String filePath;
@Value("#{jobParameters['informante']}")
private String informante;
@Autowired
RemessaParser remessaParserService;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
GICLogger.info("Recebido job com path: " + filePath + " para o informante "+ informante);
try{
Path remessa = Paths.get(filePath);
if(Files.exists(remessa)){
String idRemessa = remessaParserService.remessaReader(remessa, informante);
GICLogger.info("### TaskletStep:" + idRemessa + " é o ID da Remessa!");
return RepeatStatus.FINISHED;
}else{
GICLogger.error("Não foi possível encontrar a remessa em "+filePath);
}
}catch(Exception e){
e.printStackTrace();
}
return RepeatStatus.FINISHED;
}
}
我的启动命令:
dataflow> task launch negTask --arguments "filePath=/tmp/jars/remessa.txt informante=CaixaB --spring.cloud.task.closecontext_enable=false"
应用程序日志:
2018-04-04 13:33:28 [主要] INFO c.b.g.n.BatchNegativacaoApp - 已开始 BatchNegativacaoApp在13.938秒(JVM运行14.599)
2018-04-04 13:33:28 [主要] INFO o.s.b.a.b.JobLauncherCommandLineRunner - 运行默认命令行 with:[filePath = / tmp / jars / remessa.txt,informante = Caixa, --spring.cloud.task.closecontext_enable = false, - spring.cloud.task.executionid = 17]
2018-04-04 13:33:28 [main] INFO o.s.b.c.l.support.SimpleJobLauncher - Job:[SimpleJob:[name = job]]使用以下参数启动: [{文件路径= /家庭/恩里科/ PROJETOS / GIC / JAVA / remessa.txt, -spring.cloud.task.executionid = 8,informante = Caixa,-spring.cloud.task.closecontext_enable = false,run.id = 12,time = 1522842134819}]
你们有没有想过它为什么会发生?
感谢您的关注和任何意见!
祝你好运, 恩里科
答案 0 :(得分:2)
Enrico boa tarde,tive um problema semelhante,resolvi da seguinte forma。
@Bean
@Qualifier("load")
public Job load(JobCompletionNotificationListener listener, Step step1,
@Qualifier("stepValidation") Step stepValidation) {
return jobBuilderFactory.get("load")
.incrementer(new SampleIncrementer())
.listener(listener)
.flow(stepValidation)
.next(step1)
.end().build();
}
public class SampleIncrementer implements JobParametersIncrementer {
public JobParameters getNext(JobParameters parameters) {
if (parameters==null || parameters.isEmpty()) {
return new JobParametersBuilder().addLong("run.id", 1L).toJobParameters();
}
long id = parameters.getLong("run.id",1L) + 1;
return new JobParametersBuilder().addLong("run.id", id)
.toJobParameters();
}
}