spring-bootmigrationspring-batchspring-batch-tasklet

Issue with BatchMetaDataConfiguration when upgrading Spring Batch version 4.x to 5.x


`I have the below class to configure my Meta Data information of the jobs that are running. As part of Spring Batch 5 I understand "MapJobRepositoryFactoryBean" is no longer available. What is the alternative for this and how do I implement the below feature?

@Configuration
@EnableBatchProcessing
public class BatchMetaDataConfiguration {

@Bean
public ResourcelessTransactionManager transactionManager() {
return new ResourcelessTransactionManager();
}

@Bean
public MapJobRepositoryFactoryBean mapJobRepositoryFactory
(ResourcelessTransactionManager   txManager)
throws Exception {
MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(txManager);
factory.afterPropertiesSet();
return factory;
}

@Bean
public JobRepository jobRepository(MapJobRepositoryFactoryBean factory) throws Exception {
return factory.getObject();
}

@Bean
public JobExplorer jobExplorer(MapJobRepositoryFactoryBean factory) {
return new SimpleJobExplorer(factory.getJobInstanceDao(), factory.getJobExecutionDao(),
factory.getStepExecutionDao(), factory.getExecutionContextDao());
}

@Bean
public SimpleJobLauncher jobLauncher(JobRepository jobRepository) {
SimpleJobLauncher launcher = new SimpleJobLauncher();
launcher.setJobRepository(jobRepository);
return launcher;
}

}

I gone through the migration guide and the examples for Spring Batch 5.0 but still not not find a solution for this problem.


Solution

  • What is the alternative for this and how do I implement the below feature?

    The alternative is to use the JDBC job repository implementation with an in memory database. This is is mentioned in the migration guide: https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide#job-repositoryexplorer-configuration-updates