Best approach to pass data between ItemProcessors in spring batch?
I need to pass data related to processing an item in between item processors, I don't need to persist the data, what is the best approach (Note I'm currently using StepSynchronizationManager to access the stepExec开发者_StackOverflowution and store the data in ExecutionContext).
What makes you think, that your way - storing the data in StepExecutionContext - is a bad or not the best way ?
You could try it without saving the data in the StepExecution and instead change the items between the processors
public class FirstProcessor implements ItemProcessor<String, String> {...}
public class SecondProcessor implements ItemProcessor<String, OtherClass> {
public OtherClass process(String item) throws Exception {
return otherClassObjectWithDataForNextProcessor;
}
}
public class ThirdProcessor implements ItemProcessor<OtherClass, TargetClass> {...}
public class CustomItemWriter implements ItemWriter<TargetClass> {...}
see Spring Batch Doc - Chaining Item Processors
精彩评论