在春季批处理中将数据传递给子作业

时间:2020-10-21 15:32:10

标签: spring-batch

我有创建2个分离的作业job1和Job2。然后Job1调用Job2作为jobStep。

这是我的Job1配置

@Bean
public Job job() {
    return jobBuilderFactory.get("job1")
            .start(step())
            .next(step2())
            .next(stepa())
            .build();
}


@Bean Step stepa() {
    return this.stepBuilderFactory.get("stepa")
            .job((Job) applicationContext.getBean("job2"))
            .parametersExtractor(new MyJobParametersExtractor())
            .build();
}  

对于Job2

@Bean("job2")
public Job job2() {
    return jobBuilderFactory.get("job2")
            .start(stepx()).build();
}


@Bean
public Step stepx() {
    return this.stepBuilderFactory.get("stepx")
            .tasklet( (StepContribution contribution, ChunkContext chunkContext)  -> {
                System.out.println(chunkContext.getStepContext().getJobName());
                String name = (String) chunkContext.getStepContext()
                        .getJobParameters()
                        .get("name");
                System.out.println(chunkContext.getStepContext().getStepExecution().getJobExecution().getJobParameters());
                return RepeatStatus.FINISHED;
            }).build();
}  

请问有人可以告诉我如何将数据从Job1传递到Job2吗?

0 个答案:

没有答案