Im new to spring batch and was just looking for some help passing a list between steps. In my step 1 writer I am adding a list to the ExecutionContext.
ExecutionContext stepContext = this.stepExecution.getExecutionContext();
stepContext.put("messageList", messages);
In my reader from step two I am getting the data back by doing:
JobExecution jobExecution = stepExecution.getJobExecution();
ExecutionContext jobContext = jobExecution.getExecutionContext();
this.messages= jobContext.get("messageList");
This works and i get the list but the issue I am having is that I want to pass this list onto the processor but the read() method from the ItemReader loops continuously returning the list where as I only want to return the list once. As it is doing this the processor loops also. Is there a way I can pass the list to the reader in step two without the read() method doing this? Bellow is my message reader
public class MessageReader implements ItemReader<Object> {
private Object messages;
@Override
public Object read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
return messages;
}
@BeforeStep
public void retrieveSharedStepDate(StepExecution stepExecution){
JobExecution jobExecution = stepExecution.getJobExecution();
ExecutionContext jobContext = jobExecution.getExecutionContext();
this.messages= jobContext.get("messageList");
}
So basically what im trying to do is get my reader in step two to read the list that is produced from my writer in step one.