Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to place @EnableBatchProcessing?

I'm using spring-batch for job executions. Does it matter on which class I place the @EnableBatchProcessing(modular = true) annotation?

I would place it on the global ApplicationConfig, or would it be better to put it on the modular batch configuration where the batch job execution context is created? Eg:

@Configuration
public class ModularBatchConfig {
    @Bean
    public ApplicationContextFactory myJob() {
       return new GenericApplicationContextFactory(MyJob.class);
    }
}
like image 875
membersound Avatar asked Sep 15 '25 16:09

membersound


1 Answers

In an "application" that contains multiple batch jobs, we recommend putting the @EnableBatchProcessing at the highest level that makes sense. What I mean by that is that @EnableBatchProcessing is going to bootstrap a number of common components (JobRepository, TransactionManager, etc). It's typically better to use these as common components instead of bootstrapping one per job.

like image 84
Michael Minella Avatar answered Sep 18 '25 06:09

Michael Minella