当我 "fib" reader 时,Spring 步骤没有 运行 正确,我必须使用 tasklet 吗?

Spring step does not run properly when I "fib" the reader, must I use a tasklet?

我知道所有 spring 步骤都需要一个 reader、一个编写器和一个可选的处理器。所以即使我的步骤只需要一个作家,我也在撒谎 reader 除了让 spring 快乐之外什么都不做。

这是基于 here 找到的解决方案。它是否过时了,还是我遗漏了什么?

我有一个 spring 批处理作业,它有两个分块步骤。我的第一步 deleteCount 只是删除 table 中的所有行,以便第二步有一个干净的平板。这意味着我的第一步不需要 reader,所以我按照上面链接的 Whosebug 解决方案创建了一个 NoOpItemReader,并将其添加到我的 stepbuilder 对象(代码在底部) .

我的编写器被映射到一个简单的 SQL 语句,该语句从 table 中删除所有行(代码在底部)。

我的 table 没有被 deleteCounts 步骤清除。我怀疑是因为我在撒谎 reader.

我期待 deleteCounts 会删除 table 中的所有行,但它不是 - 我怀疑这是因为我的 "fibbed" reader 但是我不确定我做错了什么。

我的删除语句:

<delete id="delete">
    DELETE FROM ${schemaname}.DERP
</delete>

我的 deleteCounts 步骤:

@Bean
@JobScope
public Step deleteCounts() {
    StepBuilder sb = stepBuilderFactory.get("deleteCounts");
    SimpleStepBuilder<ProcessedCountData, ProcessedCountData> ssb = sb.<ProcessedCountData, ProcessedCountData>chunk(10);
    ssb.reader(noOpItemReader());
    ssb.writer(writerFactory.myBatisBatchWriter(COUNT_DATA_DELETE));
    ssb.startLimit(1);
    ssb.allowStartIfComplete(true);
    return ssb.build();
}

我的 NoOpItemReader,基于之前在 Whosebug 上链接的解决方案:

public NoOpItemReader<? extends ProcessedCountData> noOpItemReader() {
    return new NoOpItemReader<>();
}

// for steps that do not need to read anything
public class NoOpItemReader<T> implements ItemReader<T> {

    @Override
    public T read() throws Exception {
        return null;
    }
}

我遗漏了一些 mybatis 管道,因为我知道它正在工作(第 2 步更多地涉及 mybatis 的东西,第 2 步插入行就好了。删除是如此简单,它一定是我的东西步骤配置...)

你的 NoOpItemReader returns nullItemReader 返回 null 表示输入已用完。由于在您的情况下,仅此而已 returns,框架假定首先没有输入。