Spring Batch: transmettre des données entre le lecteur et l'écrivain

Je voudrais obtenir les données de l'Écrivain que je l'ai mis dans le Lecteur de mon étape. Je sais que sur ExecutionContexts (de l'étape et de l'emploi) et sur ExecutionContextPromotionListener via http://docs.spring.io/spring-batch/trunk/reference/html/patterns.html#passingDataToFutureSteps

Le problème est que, dans l'Écrivain, je suis de la récupération d'une valeur nulle de "gnap'.

Ligne sur ItemWriter:

LOG.info("INSIDE WRITE, NPAG: " + nPag);

J'ai fait quelques solutions de contournement, mais sans succès, à la recherche de réponses pour d'autres des questions similaires... Toute aide? merci!

Voici mon code:

LECTEUR

@Component
public class LCItemReader implements ItemReader<String> {

private StepExecution stepExecution;

private int nPag = 1;

@Override
public String read() throws CustomItemReaderException {

    ExecutionContext stepContext = this.stepExecution.getExecutionContext();
    stepContext.put("npag", nPag);
    nPag++;
    return "content";
}

@BeforeStep
public void saveStepExecution(StepExecution stepExecution) {
    this.stepExecution = stepExecution;
}
}

ÉCRIVAIN

@Component
@StepScope
public class LCItemWriter implements ItemWriter<String> {

private String nPag;

@Override
public void write(List<? extends String> continguts) throws Exception {
    try {
        LOG.info("INSIDE WRITE, NPAG: " + nPag);
    } catch (Throwable ex) {
        LOG.error("Error: " + ex.getMessage());
    }
}

@BeforeStep
public void retrieveInterstepData(StepExecution stepExecution) {
    JobExecution jobExecution = stepExecution.getJobExecution();
    ExecutionContext jobContext = jobExecution.getExecutionContext();
    this.nPag = jobContext.get("npag").toString();
}
}

TRAVAIL/ÉTAPE DE LOT CONFIG

@Bean
public Job lCJob() {
    return jobs.get("lCJob")
            .listener(jobListener)
            .start(lCStep())
            .build();
}

@Bean
public Step lCStep() {
    return steps.get("lCStep")
            .<String, String>chunk(1)
            .reader(lCItemReader)
            .processor(lCProcessor)
            .writer(lCItemWriter)
            .listener(promotionListener())
            .build();
}

AUDITEUR

@Bean
public ExecutionContextPromotionListener promotionListener() {
    ExecutionContextPromotionListener executionContextPromotionListener = new ExecutionContextPromotionListener();
    executionContextPromotionListener.setKeys(new String[]{"npag"});
    return executionContextPromotionListener;
}
  • Injecter de l'exécution étape par étape dans l'écrivain et de lire gnap au cours de l'écriture()
InformationsquelleAutor Emilio | 2015-09-23