我知道所有 spring 步骤都需要有一个阅读器,一个写入器和一个处理器 . 因此,尽管我的步骤只需要一位作家,但我也在努力让读者无所事事,只会让 Spring 天快乐 .
这是基于找到的解决方案here . 它已经过时了,还是我错过了什么?
我有一个 spring 批处理作业,有两个分块步骤 . 我的第一步, deleteCount
,只是删除表中的所有行,以便第二步有一个干净的平板 . 这意味着我的第一步不需要读者,所以我按照上面链接的stackoverflow解决方案创建了一个 NoOpItemReader
,并将其添加到我的 stepbuilder
对象(底部的代码) .
我的编写器映射到一个简单的SQL语句,删除表中的所有行(代码位于底部) .
我的表未被 deleteCounts
步骤清除 . 我怀疑它对读者不屑一顾 .
我期待 deleteCounts
将删除表中的所有行,但它不是 - 我怀疑它's because of my 2771266 reader but am not sure what I'我做错了 .
我的删除声明:
<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,基于stackoverflow上以前链接的解决方案:
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步是插入行就好了 . 删除很简单,它必须是我的步骤配置... )
1 回答
您的
NoOpItemReader
返回null
.ItemReader
返回null
表示输入已用尽 . 因为,在你的情况下,这就是它返回的所有内容,因此框架假设首先没有输入 .