Java Reference
In-Depth Information
@BeforeStep , @AfterStep , @BeforeChunk , and @AfterChunk annotations to simplify the implementation.
Listing 4-38 shows a StepListener that uses annotations to identify the methods.
Listing 4-38. Logging Step Start and Stop Listeners
package com.apress.springbatch.chapter4;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.annotation.AfterStep;
import org.springframework.batch.core.annotation.BeforeStep;
public class LoggingStepStartStopListener {
public void beforeStep(StepExecution execution) {
System.out.println(execution.getStepName() + “ has begun!");
public ExitStatus afterStep(StepExecution execution) {
System.out.println(execution.getStepName() + “ has ended!");
return execution.getExitStatus();
The configuration for all the step listeners is combined into a single list in the step configuration.
Similar to the job listeners, inheritance works the same way, allowing you to either override the list or
merge them together. Listing 4-39 configures the LoggingStepStartStopListener that you coded earlier.
Listing 4-39 . Configuring LoggingStepStartStopListener
<beans:bean id="loggingStepListener"
<job id="stepListenerJob">
<step id="step1">
<chunk reader="inputReader" writer="outputWriter"
<listener ref="loggingStepListener"/>
As you can see, listeners are available at just about every level of the Spring Batch framework to
allow you to hang processing off your batch jobs. They're commonly used not only to perform some
Search WWH ::

Custom Search