I use Spring Batch 4.3.2. I need to define a TaskExecutor for the JobLauncher. As i don't want to enable bean overriding, the solution with DefaultBatchConfigurer is not applicable. I ended up with the the beans below, defining all bean on my own. My Question:
- Do you see an other solutions than mine?
- Are the beans defined the correct way?
Thanks for your help! Cheers T
@Bean
public JobBuilderFactory jobBuilderFactory(JobRepository jobRepository) {
return new JobBuilderFactory(jobRepository);
}
@Bean
public StepBuilderFactory stepBuilderFactory(JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new StepBuilderFactory(jobRepository, transactionManager);
}
@Bean
public JobRegistry jobRegistry() {
return new MapJobRegistry();
}
@Bean
public JobRepository createJobRepository(DataSource dataSource, PlatformTransactionManager transactionManager) throws Exception {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(dataSource);
factory.setTransactionManager(transactionManager);
factory.afterPropertiesSet();
return factory.getObject();
}
@Bean
public JobExplorer createJobExplorer(DataSource dataSource) throws Exception {
JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean();
jobExplorerFactoryBean.setDataSource(dataSource);
jobExplorerFactoryBean.afterPropertiesSet();
return jobExplorerFactoryBean.getObject();
}
@Bean
public JobLauncher jobLauncher(ThreadPoolTaskExecutor taskExecutor, JobRepository jobRepository) throws Exception {
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
jobLauncher.setJobRepository(jobRepository);
jobLauncher.setTaskExecutor(taskExecutor);
jobLauncher.afterPropertiesSet();
return jobLauncher;
}
@Bean
public ThreadPoolTaskExecutor msBatchTaskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(50);
taskExecutor.setQueueCapacity(50);
return taskExecutor;
}
As i don't want to enable bean overriding, the solution with DefaultBatchConfigurer is not applicable: I'm curious about the reason for that. Is there is something wrong with bean overriding? What you would you suggest if the solution withBatchConfigureris not applicable? I'm open for ideas to improve things if possible.