我想将 Spring Batch 配置为在作业开始时发送电子邮件,并在作业完成或失败时发送电子邮件。我通过搜索看到了一些示例,例如codecentric 上的链接,但我没有在我的项目中使用 XML 注释。
我有一个看起来像这样的听众,但不确定我可能需要什么其他作品。任何输入将不胜感激
public class SendMailListener implements JobExecutionListener {
final static Logger LOGGER = LoggerFactory.getLogger(SendMailListener.class);
@Autowired
private JobExplorer explorer;
@Autowired
private StepExecution stepExecution;
@Override
public void afterJob(JobExecution jobExecution) {
if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
LOGGER.info("The job has been completed with the following parameters: " + jobExecution.getJobParameters());
}
//send email here
}
@Override
public void beforeJob(JobExecution jobExecution) {
// TODO Auto-generated method stub
}
//send email here
}
编辑:
我有与听众一起定义的工作:
@Bean(name = "mccINSTANCETESTjob")
public Job mccOrz004job(JobBuilderFactory jobFactory, //
@Qualifier("instanceTestSetupStep") Step orz004SetupStep, //
@Qualifier("callM204Step") Step callM204Step, //
@Autowired SingleInstanceListener listener, @Autowired SendMailListener mailListener) { //
return jobFactory.get("mccINSTANCETESTjob") //
.incrementer(new RunIdIncrementer()) //
.listener(mailListener) //
.start(orz004SetupStep) //
.next(callM204Step) //
.build();
}
慕码人2483693
交互式爱情
相关分类