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

后端 未结 1 1391
梦谈多话
梦谈多话 2021-02-05 09:41

For now, I\'m using jobParameters to get the filenames for both my FlatFileItemReader and FlatFileItemWriter. It\'s okay for testing my batch, but my goal is to read a file in s

相关标签:
1条回答
  • 2021-02-05 09:59

    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);

    0 讨论(0)
提交回复
热议问题