无法调用方法异常:@afterstep in itemwriter

niwlg2el  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(161)

我的批处理作业读取、处理和写入数据库。作业运行正常时 ItemProcessor 返回至少一项。如果返回null,则
ItemWriter @AfterStep 无法调用方法。
这是密码

public class BlockItemWriter implements ItemWriter<Block> {

@Override
public void write<List<? extends Block> items) throws Exception {
//do something
}

@BeforeStep
public void beforeStepExec(StepExecution stepExecution){
    this.stepExecution = stepExecution; }

@AfterStep
public void afterStepExec(StepExecution stepExecution){
    //Access step execution context
    //do something}
}

下面的工作项处理器

public class BlockItemProcessor implements ItemProcessor<Block> {

@Override
public Block process(Block item) throws Exception {
return item;
}

@BeforeStep
public void beforeStepExec(StepExecution stepExecution){
    this.stepExecution = stepExecution; }

}

以下itemprocessor代码的itemWriter@afterstep中引发异常

public class BlockItemProcessor implements ItemProcessor<Block> {

@Override
public Block process(Block item) throws Exception {
return null;
}

@BeforeStep
public void beforeStepExec(StepExecution stepExecution){
    this.stepExecution = stepExecution; }

}

为什么我要用null测试?处理器有过滤条件。它是-在itemprocessor用例测试中通过过滤跳过所有项。在实际场景中,在100个项目中,即使有1个项目没有被过滤掉,也不会抛出异常。只有在处理器中过滤了所有100项时,才会发生异常,。
有没有跳过的选项 ItemWriter 如果 ItemProcessor 过滤掉所有块的所有记录。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题