I have some spring batch jobs that the most of the configuration are the same and have some small changes like the query or item reader. I saw some job and step inheritance using Xml config like this , but I'm looking for similar functionality using spring batch configs E.G, (jobBuilderFactory and StepBuilderFactory). Heare is my job config:
@Bean
public Job job()
{
return jobBuilderFactory.get("job")
.start(master())
.incrementer(new RunIdIncrementer())
.build();
}
and this is one of steps:
@Bean
public Step workerStep()
{
return stepBuilderFactory.get("workerStep")
.<Subscription,ProcessorDto>chunk(chunkSize)
.reader(reader())
.writer(writer())
.processor(processor())
.faultTolerant()
.skip(RuntimeException.class)
.skipLimit(skipLimit)
.build();
}
Thanks in advance for your time and attention.
CodePudding user response:
There is no equivalent to the XML bean definition inheritance in the Java configuration style. There is no need for that since one can use the built-in inheritance in Java, see Bean definition inheritance with annotations?. The JobBuilderFactory
provided by Spring Batch can be extended to create JobBuilder
s with common properties, and then the common builder could be used for specific job definitions (same for steps).
You can check this article which provides more details and code examples of how to achieve that. The credit goes to @tobias-flohre for that great blog post series on Spring Batch.