0

在 SpringBatch 中,作业没有按照定义的步骤完成,而是继续从 Writer 到 Reader,而 Debugging 发现的上下文计数增加为 1
,因为执行状态为“CONTINUABLE”而不是“FINISHED”。

第 1 步即将完成,但第 2 步遇到此问题..请帮助..

@Configuration
@Log4j2
public class PickUpBatchConfig {

    @Autowired
    public JobBuilderFactory jobBuilderFactory;

    @Autowired
    public StepBuilderFactory stepBuilderFactory;

    private StepExecution stepExecution;


    @Bean
    public Job pickupJob() {
        return this.jobBuilderFactory.get("pickupJob")
            .incrementer(new RunIdIncrementer())
            .listener(new JobResultListener())
            .start(readAndFilterBlockInventoryExtract())
            .next(blockKeyFetch())
            .next(processRequest())
           // .next(sendMessage())
            .build();
    }

    @Bean
    public StepResultListener customStepListener() {
        return new StepResultListener();
    }

    @Bean
    public Step readAndFilterBlockInventoryExtract() {
        System.out.println("*****PickUpBatchConfig.readAndFilterBlockInventoryExtract********");
        return this.stepBuilderFactory.get("step1")
            .<BlockInventoryExtractProcessRequest<ProcessRequest>, BlockInventoryExtractProcessor.BlockInventoryExtractBuilder>chunk(0)
            .reader(new BlockInventoryReader())
            .processor(processor())
            .writer(new BlockInventoryWriter())
            .listener(promotionListener())
            .build();
    }

    @Bean
    public ExecutionContextPromotionListener promotionListener() {
        ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
        listener.setKeys(new String[] {"builder"});
        listener.setStrict(true);
        return listener;
    }


    @Bean
    public ItemProcessor<BlockInventoryExtractProcessRequest<ProcessRequest>, BlockInventoryExtractProcessor.BlockInventoryExtractBuilder> processor() {
        return new BatchBlockInventoryExtractProcessor();
    }



    @Bean
    public Step blockKeyFetch() {
        System.out.println("PickUpBatchConfig.blockKeyFetch");
        return this.stepBuilderFactory.get("step2")
            .<BlockInventoryExtractProcessor.BlockInventoryExtractBuilder,BlockInventoryExtractProcessor.BlockInventoryExtractBuilder>chunk(1)
            .reader(new BlockKeyReader())// Need to implement
            .processor(step2processor())
            .writer(new BlockKeyWriter())
            .listener(promotionListenerStep2())
            .build();
    }

    @Bean
    public ExecutionContextPromotionListener promotionListenerStep2() {
        ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
        listener.setKeys(new String[] {"blockKey"});
        listener.setStrict(true);
        return listener;
    }

    @Bean
    public ItemProcessor<BlockInventoryExtractProcessor.BlockInventoryExtractBuilder,BlockInventoryExtractProcessor.BlockInventoryExtractBuilder> step2processor() {
        return new BlockKeyProcess();
    }

    @Bean
    public Step processRequest() {
        System.out.println("PickUpBatchConfig.processRequest");
        return this.stepBuilderFactory.get("step3")
            .<BlockInventoryExtractProcessor.BlockInventoryExtractBuilder, List<BlockInventoryExtractProcessRequest>>chunk(0)
            .reader(new ProcessRequestReader())//need to implement
            .processor(new ProcessRequestProcessor())
            .writer(new ProcessRequestWriter())
            .listener(promotionListenerStep3())
            .build();
    }

    @Bean
    public ExecutionContextPromotionListener promotionListenerStep3() {
        ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener();
        listener.setKeys(new String[] {"processRequest"});
        listener.setStrict(true);
        return listener;
    }
4

0 回答 0