this problem arises because springBoot considers the initially configured beans as the primary beans and by default , accounts for only one configuration class for SpringBatch. Hence , if the initially defined batchJob configuration is already there , it will require some differentiation between multiple batch configuration classes.
there are many solutions to this problem :
-> Making the beans defined in the batchConfiguration files as primary by adding @Primary annotation , so that springBoot can differentiate between the primary and secondary beans .
But , it would give us problems if there are more than two configuration files present in the scenario.
Hence the usage of @Qualifier annotation will be the best suited option .
@Bean
@Qualifier("jsonProcessingJobBeanV1")
public Job jsonProcessingJob(JobRepository jobRepository, Step jsonProcessingStep) {
return new JobBuilder("jsonProcessingJob", jobRepository)
.incrementer(new RunIdIncrementer())
.listener(jobExecutionListener())
.start(jsonProcessingStep)
.build();
}
and similarly for the stepBuilder , ItemReader , ItemWriter and ItemProcessor also , we will define the @Qualifier names.
Example (ItemReader) :
@Bean
@Qualifier("ItemReaderV1")
@StepScope
public ItemReader<ItemEntity> jsonItemReader(@Value("#{jobParameters['fileName']}") String fileName) {
In the same manner we are supposed to annotate all the beans. And your problem will be solved .