DataSourceTransactionManager bean not created after Introducing Spring Batch @EnableBatchProcessing Annotation

640 views Asked by At

I am integrating Spring Batch in one of the existing applications where other beans are successfully using DataSourceTransactionManager. However, I am getting the following error when I introduce the @EnableBatchProcessing annotation :

Field transactionManager in AuthBeans required a bean of type 'org.springframework.jdbc.datasource.DataSourceTransactionManager' that could not be found.

I've tried to configure BatchConfigurer but it has not resolved the issue. Please see BatchConfigurer code below.

@Configuration
public class CustomBatchConfigurer implements BatchConfigurer {


    @Autowired
    private DataSource dataSource;


    @Override
    public JobRepository getJobRepository() throws Exception {
        JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
        factory.setDataSource(dataSource);
        factory.setTransactionManager(getTransactionManager());
        factory.afterPropertiesSet();
        return  (JobRepository) factory.getObject();
    }

    @Override
    public PlatformTransactionManager getTransactionManager() throws Exception {
        return new DataSourceTransactionManager(dataSource);
    }

    @Override
    public JobLauncher getJobLauncher() throws Exception {
        SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
        jobLauncher.setJobRepository(getJobRepository());
        jobLauncher.afterPropertiesSet();
        return jobLauncher;
    }

    @Override
    public JobExplorer getJobExplorer() throws Exception {
        JobExplorerFactoryBean factory = new JobExplorerFactoryBean();
        factory.setDataSource(dataSource);
        factory.afterPropertiesSet();
        return  (JobExplorer) factory.getObject();
    }

I am wondering am I missing something? Your help regarding this will be highly appreciated.

1

There are 1 answers

1
Garikina Rajesh On

In which class , you kept @EnableBatchProcessing annotation. @EnableBatchProcessing should be at the highest level.

@EnableBatchProcessing will create the DataSourceTransactionManager by default.

Go through this BatchConfigure and follow the example.

I hope this will resolve your issue.