【发布时间】:2017-08-31 20:09:35
【问题描述】:
我有一个简单的 Spring Batch 作业,有几个步骤,最后一步是编写报告,所以我有 ItemReader、ItemProcessor 和 ItemWriter。 ItemWriter 按块写入取决于步骤中定义的块编号,但我需要等到获取所有项目然后写入最终报告。我怎样才能做到这一点?
public class ReportItemWriter implements ItemWriter<ReportItem> {
private List<ReportItem> allItems = Lists.newArrayList();
...
public void write(List<? extends ReportItem> reportItems) throws Exception {
allItems.addAll(reportItems);
writeReport(allItems); <-- here it only write chunk of items to the report
}
【问题讨论】:
-
报告中需要哪些信息?你确定不能逐块合成吗?
-
您可以在 close() 方法中实现 ItemStreamWriter 并构建写入最终报告。写入所有项目时将调用该方法。如果您需要更多详细信息,例如代码,请告诉我...
标签: java spring-batch