0
votes

I wanted to Persist Spring Batch Meta Data related to Jobs/Steps instead of Using MapJobRepository, as it is not recommended for Production Use.
I have extended DefaultBatchConfigurer and have overridden the methods to use My Primary DataSource and Transaction Manager by using JobRepositoryFactoryBean.
Also i have Registered SimpleJobLauncher bean to use custom job repository , for which i have used the below code

@Bean
SimpleJobLauncher simpleJobLauncher() throws Exception {
    SimpleJobLauncher simpleJobLauncher= new SimpleJobLauncher();
    simpleJobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
    simpleJobLauncher.setJobRepository(customRepository());
    return simpleJobLauncher;
}

@Bean
public JobRepository customRepository() throws Exception {
JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean();
jobRepositoryFactoryBean.setDataSource(myPrimaryDataSource);
jobRepositoryFactoryBean.setTransactionManager(myTransactionManager);
jobRepositoryFactoryBean.setDatabaseType("MYSQL");
jobRepositoryFactoryBean.setTablePrefix("BATCH_");
jobRepositoryFactoryBean.setMaxVarCharLength(1000);
return jobRepositoryFactoryBean.getObject();
}

I am facing with below exception when i launch the job

java.lang.NullpointerException:null
    at org.springframework.batch.core.repository.dao.MapJobExecutionDao:synchronizeStatus(MapJobExecutionDao.java 161)

Please do let me know where exactly my configuration is wrong.

1
@MahmoudBenHassine Can you Please throw some light on this.. - trackex trackex

1 Answers

0
votes

From your exception, it looks like Spring Batch is configured to use the Map based job repository and not the persistent one.

Since you extended DefaultBatchConfigurer, you need to override createJobRepository and return your custom job repository. Declaring a bean of type JobRepository in the application context is not sufficient.