0
我想將一些信息從一個步驟傳遞到批處理作業中的另一個步驟。創建BStepListener,其中存儲上下文的值,但該相同的值不會到達在另一個步驟中創建的tasklet [SendMailTasklet]。我在哪裏失蹤?無法使用ExecutionContextPromotionListener在目標步驟中接收值
作業配置
<job id="bJob" xmlns="http://www.springframework.org/schema/batch">
<step id="step1">
<tasklet>
<chunk reader="bReader" writer="bWriter" processor="bProcessor"
commit-interval="10" />
</tasklet>
<batch:next on="COMPLETED" to="sendEmail"/>
<listeners>
<listener ref="bStepListner"/>
<listener ref="bPromotionListener"/>
</listeners>
</step>
<step id="sendEmail">
<tasklet ref="sendMailManager"/>
</step>
</job>
<bean id="bStepListner" class="com.listener.BStepListener" scope="step"/>
<bean id="bPromotionListener" class="org...ExecutionContextPromotionListener">
<property name="keys" value="msg"/>
</bean>
<bean id="sendMailManager" class="com.mail.SendMailTasklet" scope="step">
BStepListener.java
public ExitStatus afterStep(StepExecution stepExecution) {
System.out.println("Step Execution Listener ... after Step");
String message = "A Sample message from step to step";
stepExecution.getExecutionContext().put("msg", message);
return null;
}
SendMailTasklet.java
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext)
throws Exception {
logger.info("Sending Email service....");
String message = (String)chunkContext.getStepContext().getJobExecutionContext().get("msg");
this.sendMail();
return RepeatStatus.FINISHED;
}
完美。有效。我不能投票少的名聲。 – 2014-10-28 17:58:41