-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Spring Batch has always provided a default way to configure infrastructure beans (historically DefaultBatchConfigurer
in v3 and v4 which was slightly improved and muted to DefaultBatchConfiguration
in v5). However, the way this default configuration is designed to be customized through inheritance is problematic (for all the known limitations of inheritance like multiple inheritance for instance).
In v6, I suggest to change the way the default configuration is used: instead of extending it, it should rather be imported. Therefore, users can compose the batch configuration by importing classes rather than extending them. For example, instead of doing this:
@Configuration
public class MyJobConfiguration extends DefaultBatchConfiguration {
@Bean
public Job job(JobRepository jobRepository) {
return new JobBuilder("myJob", jobRepository)
// define job flow as needed
.build();
}
}
users can do this:
@Configuration
@Import(DefaultBatchConfiguration.class)
public class MyJobConfiguration {
@Bean
public Job job(JobRepository jobRepository) {
return new JobBuilder("myJob", jobRepository)
// define job flow as needed
.build();
}
}
If custom batch scopes are needed, they can be imported in addition to the default configuration:
@Configuration
@Import({DefaultBatchConfiguration.class, ScopeConfiguration.class})
public class MyJobConfiguration {
@Bean
public Job job(JobRepository jobRepository) {
return new JobBuilder("myJob", jobRepository)
// define job flow as needed
.build();
}
}
This way, the configuration can be composed (with fine-grained components) rather than inherited from a base class and customised by overriding getters. Customization can be achieved by bean lookup from the application context (similar to / consistent with @EnableBatchProcessing
).