Add parameter to job context from tasklet step and use in later steps in Spring Batch

梦想与她 提交于 2019-12-03 10:50:00

In tasklet you have ChunkContext at your disposal so you do not need @BeforeStep, you can remove it (in my configuration it is not invoked at all, and when you think of it as one action step does not make much sense but I do not see NPE so guess that part work). We solved it with one of two approaches:

  1. You can put any parameter from tasklet to job ExecutionContext directly using chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("inputFile", inputFilename);

  2. You can add ExecutionContextPromotionListener to your tasklet step and then do chunkContext.getStepContext().getStepExecution().getExecutionContext().put("inputFile", inputFilename);

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