I am migrating my spring boot spring batch application from spring batch 4.x to 5.1.1 (this is part of spring boot 2.7.18 to 3.2.4 migration).
In our batch application we do not use any spring batch internal table (that spring batch uses). On migrating to spring batch 5.1.1 the usage of these internal table seems to be the default behavior which I think was not the case in 4.x)
My Job Configuration looks like below –
@EnableBatchProcessing()
public class BatchJobConfiguration{
@Bean
public JobRepository JobRepository() {
return new JobRepositoryImpl();
}
@Bean
@StepScope
public ItemWriter<BatchFileRecord> writer(@Value("#{stepExecution['jobExecution']}") JobExecution jobExecution) {
ItemWriter<BatchFileRecord> writer = new BatchFileRecordItemWriter().withJobExecution(jobExecution);
return writer;
}
@Bean
public Job processBatchFileJob(JobCompletionNotificationListener listener, Step step1) {
return new JobBuilder(PROCESS_BATCH_FILE_JOB_NAME, JobRepository())
.listener(listener)
.flow(step1)
.end()
.build();
}
@Bean
ItemReader<Pair<String[], Integer>> reader, PlatformTransactionManager transactionManager) {
public Step step1(PlatformTransactionManager transactionManager, ItemReader<Pair<String[], Integer>> reader,BatchFileItemProcessor processor, ItemWriter<BatchFileRecord> writer) {
return new StepBuilder("step1", JobRepository())
.<Pair<String[], Integer>, BatchFileRecord>chunk(chunkSize, transactionManager)
.reader(reader)
.processor(processor)
.writer(writer)
.taskExecutor(executor)
.throttleLimit(throttleLimit)
.build();
}
@Bean
@Lazy
public JobLauncher JobLauncher() {
ServiceJobLauncher jobLauncher = new ServiceJobLauncher();
try {
jobLauncher.setJobRepository(JobRepository());
jobLauncher.setTaskExecutor(executor);
jobLauncher.afterPropertiesSet();
} catch (Exception e) {
systemLogger().error(COMPONENT_ID, "JobLauncherException",
"Failed to set Job Launcher properties" + e);
appLogger().error(COMPONENT_ID, "JobLauncherException",
"Failed to set Job Launcher properties" + e);
}
return jobLauncher;
}
}
In 5.1.1 as you can see in StepBuilder
is now using JobRepository jobRepository
and PlatformTransactionManager transactionManager
, which was not the case in 4.x.
On executing above job.
i am facing below error –
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'
Clearly Spring Batch 5.1.1 required datasourceBean. Is there any way to exclude/avoid datasource for spring batch?
Sachin Bisht is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1