开发者

Best approach to pass data between ItemProcessors in spring batch?

开发者 https://www.devze.com 2023-03-29 12:40 出处:网络
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 acce

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

0

精彩评论

暂无评论...
验证码 换一张
取 消