I am using Spring Batch to read some data from CSV files and put it in a database. My Batch job must be compound of 2 steps :
- Check files (names, extension, content ..)
- Read lines from CSV and save them in DB (ItemReader, ItemProcessor, ItemWriter..)
Step 2
must not be executed if Step 1
generated an error (files are not conform, files doesn't exist ...)
FYI, I am using Spring Batch without XML configuration ! Only annotations : Here's what my job config class looks like :
@Configuration
@EnableBatchProcessing
public class ProductionOutConfig {
@Autowired
private StepBuilderFactory steps;
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private ProductionOutTasklet productionOutTasklet;
@Autowired
private CheckFilesForProdTasklet checkFilesForProdTasklet;
@Bean
public Job productionOutJob(@Qualifier("productionOut")Step productionOutStep,
@Qualifier("checkFilesForProd") Step checkFilesForProd){
return jobBuilderFactory.get("productionOutJob").start(checkFilesForProd).next(productionOutStep).build();
}
@Bean(name="productionOut")
public Step productionOutStep(){
return steps.get("productionOut").
tasklet(productionOutTasklet)
.build();}
@Bean(name = "checkFilesForProd")
public Step checkFilesForProd(){
return steps.get("checkFilesForProd")
.tasklet(checkFilesForProdTasklet)
.build();
}
}