Spring Batch: Creating A Custom Job Builder
Batch jobs are created in Spring Batch using the JobBuilderFactory. A custom job builder factory can be created and re-used to allow common job configurations to be shared across all batch jobs in a project.
Example
@Configuration
public class CustomJobBuilderFactory extends JobBuilderFactory {
@Override
public JobBuilder get(final String name) {
final JobBuilder jobBuilder = super.get(name);
// register common to all jobs things here
jobBuilder.listener(commonListener);
return jobBuilder;
}
}
Implementation
@Bean
public Job exampleJob(final CustomJobBuilderFactory jbf) {
// This job now has the common listener
return jbf.get("myJob").start(myStep).build();
}
}