How does one open a Reader when implementing ItemReader in a Spring Batch project?

倖福魔咒の 提交于 2019-12-03 16:47:28

Your delegate isn't getting opened. The easiest way to address this is to update the open, close, and update methods to call the corresponding methods on the delegate as well. This also allows for restartability (which your current version would not because the state of the delegate is not being saved):

@Override
public void close() throws ItemStreamException {
   delegate.close();
}

@Override
public void open(ExecutionContext arg0) throws ItemStreamException {
    delegate.open(arg0);
}

@Override
public void update(ExecutionContext arg0) throws ItemStreamException {
    delegate.update(arg0);
}

The alternative is to register your FlatFileItemReader as a stream in your step. You'll have to pull it out to a separate bean definition if you want to go that route.

You can read more about ItemStreams and how their lifecycle works and how it is impacted via delegation here: http://docs.spring.io/spring-batch/reference/html-single/index.html#itemStream

You have to call delegate.open() to perform the open of real reader. Or you can register delegate reader as streaming to let SB manage the delegate reader stream lifecycle (read chapter 6.5)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!