你可能想看看
JobExecutionListener
这允许您在作业执行前后进行一些处理。
public class DoSomethingAroundJob implements JobExecutionListener {
public void beforeJob(JobExecution jobExecution) {
System.out.println("Called beforeJob().");
}
public void afterJob(JobExecution jobExecution) {
System.out.println("Called afterJob().");
}
}
@Bean
public Job myJob(){
return jobs.get("myJob")
.listener(new DoSomethingAroundJob())
.build();
}
您的工作可能还有其他部分,但上面只显示了一个使用JavaConfig添加侦听器的示例。