与独立读者的多个步骤

时间:2018-03-03 12:15:42

标签: java spring-batch

我有两个步骤的弹簧批作业。 所有内容都在Config Java类中配置:

class MyConfigClass {
    @Bean(name = "readerA")
    public ItemReader<ResponseObject> readerA(Environment environment, RestTemplate restTemplate) {
        return new ReaderA();
    }

    @Bean(name = "readerB")
    public ItemReader<ResponseObject> readerB(Environment environment, RestTemplate restTemplate) {
        return new ReaderB();
    }

    //Processor
    //...

    //Writer
    //...

    @Bean
    Step stepA(@Qualifier("readerA") ItemReader<ResponseObject> readerA,
                         ...) {
        return stepBuilderFactory.get("stepA")
                .<ResponseObject, ResponseObject>chunk(1)
                .reader(readerA)
                .processor(processor)
                .writer(writer)
                .build();
    }

    @Bean
    Step stepB(@Qualifier("readerB") ItemReader<ResponseObject> readerB,
                         ...) {
        return stepBuilderFactory.get("stepB")
                .<ResponseObject, ResponseObject>chunk(1)
                .reader(readerB)
                .processor(processor)
                .writer(writer)
                .build();
    }

    @Bean
    Job myJob(JobBuilderFactory jobBuilderFactory,
                       @Qualifier("stepA") Step stepA,
                       @Qualifier("stepB") Step stepB){
        return jobBuilderFactory.get("myJob")
                .incrementer(new RunIdIncrementer())
                .start(stepA)
                .next(stepB)
                .build();
    }

但是我看到它初次化了readerA两次。调试模式在readerA()中进行两次,在stepA()中进行一次,在stepB()中进行一次。

0 个答案:

没有答案