使用注释,我可以像这样创建一个侦听器实现并将其添加到XML。
public class JobLoggingListener {
@BeforeChunk
public void beforeJob(JobExecution jobExecution) {
System.out.println(jobExecution.getJobInstance().getJobName() + " is about to start");
}
@AfterChunk
public void afterJob(JobExecution jobExecution) {
System.out.println(jobExecution.getJobInstance().getJobName() + " has finished");
}
}
但是,如果我想将此添加到我的工作中,请执行类似的操作
public Job job() throws Exception {
return jobBuilderFactory.get("job")
.start(step())
.listener(new JobLoggingListener())
.build();
}
有人告诉我JobLoggingListener
必须实现JobExecutionListener
,即使我在xML中配置作业也不必实现此接口。
我缺少什么吗?