diff --git a/src/site/docbook/reference/common-patterns.xml b/src/site/docbook/reference/common-patterns.xml index 1ae483038..90609cdf8 100644 --- a/src/site/docbook/reference/common-patterns.xml +++ b/src/site/docbook/reference/common-patterns.xml @@ -537,13 +537,14 @@ during Step execution and if the Step fails, that data will be lost. - public void MyItemWriter implements ItemWriter<Object> { + public void SavingItemWriter implements ItemWriter<Object> { private StepExecution stepExecution; public void write(List<? extends Object> items) throws Exception { // ... - this.stepExecution.getExecutionContext().put("someKey", someObject); + ExecutionContext stepContext = this.stepExecution.getExecutionContext(); + stepContext.put("someKey", someObject); } @BeforeStep @@ -564,22 +565,41 @@ listeners, it must be registered on the Step. - <step id="step1"> - <tasket> - <chunk reader="reader" writer="writer" commit-interval="10"/> - <listeners> - <listener ref="promotionListener"/> - </listeners> - </tasklet> -</step> + <job id="job1"> + <step id="step1"> + <tasket> + <chunk reader="reader" writer="savingWriter" commit-interval="10"/> + <listeners> + <listener ref="promotionListener"/> + </listeners> + </tasklet> + </step> -<step id="step2"> - ... -</step> + <step id="step2"> + ... + </step> +</job> -<beans:bean id="promotionListener" +<beans:bean id="promotionListener" class="org.spr....ExecutionContextPromotionListener"> <beans:property name="keys" value="someKey"/> -</beans:bean> +</beans:bean> + + Finally, to the saved values must be retrieved from the + Job ExeuctionContext: + + public void RetrievingItemWriter implements ItemWriter<Object> { + private Object someObject; + + public void write(List<? extends Object> items) throws Exception { + // ... + } + + @BeforeStep + public void saveStepExecution(StepExecution stepExecution) { + ExecutionContext jobContext = stepExecution.getJobExecution().getExecutionContext(); + this.someObject = jobContext.get("someKey"); + } +}