首页 > 解决方案 > Spring Batch,在 writer() 中访问 StepExecution

问题描述

我最近提出了这个问题,但我认为我的目标不够明确。

我有一个由读取器、处理器和写入器组成的步骤。

writer()一个CompositeItemWriter,由两个组成JdbcBatchItemWriter。在其中一个中,我正在写入将包含一row_count列的控制表。这个值需要来自StepExecution.getReadCount().

我是 Spring Batch 的新手,所以我不确定如何添加一个可以将 a 包装StepExecution到实际编写器本身的侦听器。

感谢您的阅读。

标签: springspring-bootspring-batch

解决方案


您可以使用带@BeforeStep 注释的方法。

在写入第一项之前调用此方法,spring 应该将 StepExecution 传递给它。

@BeforeStep
public void beforeStep(StepExecution stepExecution) { ... }

推荐阅读