Java Reference
In-Depth Information
public void beforeJob(JobExecution jobExecution) {
System.out.println(jobExecution.getJobInstance().getJobName()
+ " is beginning execution");
}
public void afterJob(JobExecution jobExecution) {
System.out.println(jobExecution.getJobInstance()
.getJobName()
+ " has completed with the status " +
jobExecution.getStatus());
}
}
If you remember, the topic previously stated that Spring Batch doesn't support annotations yet for
its configuration. That was a lie. A small number of annotations are supported, and @BeforeJob and
@AfterJob are two of them. When using the annotations, the only difference, as shown in Listing 4-18, is
that you don't need to implement the JobExecutionListener interface.
Listing 4-18. JobLoggerListener.java
package com.apress.springbatch.chapter4;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.annotation.AfterJob;
import org.springframework.batch.core.annotation.BeforeJob;
public class JobLoggerListener {
@BeforeJob
public void beforeJob(JobExecution jobExecution) {
System.out.println(jobExecution.getJobInstance().getJobName()
+ " is beginning execution");
}
@AfterJob
public void afterJob(JobExecution jobExecution) {
System.out.println(jobExecution.getJobInstance()
.getJobName()
+ " has completed with the status " +
jobExecution.getStatus());
}
}
The configuration of these two options is the same in either case. Back in the world of XML, you can
configure multiple listeners in your job, as shown in Listing 4-19.
 
Search WWH ::




Custom Search