Ghassen
Ghassen

Reputation: 781

How to pass data between steps in Spring Batch

How to pass data between steps in Spring Batch job using Java configuration and not XML configuration ?

Upvotes: 2

Views: 8842

Answers (1)

Ghassen
Ghassen

Reputation: 781

Finally I found a solution to share data between steps without any XML config : First thing is to make the Tasklets classes implements StepExecutionListener and for the tasklet that's sending data put :

@Override
public void beforeStep(StepExecution stepExecution) {}

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    stepExecution.getJobExecution().getExecutionContext().putString("test_key","test_value");
    return null;
}

and the second tasklet that must get data put :

@Override
public void beforeStep(StepExecution stepExecution) {
    test = stepExecution.getJobExecution().getExecutionContext().getString("test_key");
}

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    return null;
}

Upvotes: 4

Related Questions