Spring 启动时数据流覆盖作业参数

Spring Data Flow overriding job parameters at launch

我目前在 Spring 云数据流中调用任务时遇到问题。

我在 SCDF 上注册了一个 Spring 批处理(包含单任务步骤作业)应用程序和基于此应用程序的任务定义。在我第一次启动这个任务时,我使用了两个作业 parameters/arguments。由于我现在知道的原因,我所有后续启动的参数都被我使用的第一组参数覆盖了。

我使用的是 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 [main] INFO c.b.g.n.BatchNegativacaoApp - Started BatchNegativacaoApp in 13.938 seconds (JVM running for 14.599)

2018-04-04 13:33:28 [main] INFO o.s.b.a.b.JobLauncherCommandLineRunner - Running default command line 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]] launched with the following parameters: [{filePath=/home/enrico/PROJETOS/GIC/java/remessa.txt, -spring.cloud.task.executionid=8, informante=Caixa, -spring.cloud.task.closecontext_enable=false, run.id=12, time=1522842134819}]

你们知道为什么会这样吗?

感谢您的关注和任何意见!

此致, 恩里科

嗨,恩里科,我是相似性问题,试试看它是否有效。

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