Reputation: 347
I have a Spring Batch job for reading a CSV file.
How to avoid processing the first line?
I want the Processor not reading the first line, like a heading. In this case, I want the CustomerItemProcessor not reading the first line of my CSV file.
Here the code I wrote:
@Configuration
public class ImportJobConfig {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Bean
public Job importUserJob(ItemReader<Customer> importReader) {
return jobBuilderFactory.get("importUserJob")
.incrementer(new RunIdIncrementer())
.flow(step1(importReader))
.end()
.build();
}
@Bean
public Step step1(ItemReader<Customer> importReader) {
return stepBuilderFactory.get("step1")
.<Customer, Customer>chunk(10)
.reader(importReader)
.processor(processor())
.build();
}
@Bean
@Scope(value = "step", proxyMode = ScopedProxyMode.TARGET_CLASS)
public FlatFileItemReader<Customer> importReader1(@Value("#{jobParameters[fullPathFileName]}") String pathToFile) {
FlatFileItemReader<Customer> reader = new FlatFileItemReader<>();
reader.setResource(new FileSystemResource(pathToFile));
reader.setLineMapper(new DefaultLineMapper<Customer>() {{
// doing some stuff
}});
return reader;
}
@Bean
public CustomerItemProcessor processor() {
return new CustomerItemProcessor();
}
}
Upvotes: 0
Views: 4891
Reputation: 1005
You could use the FlatFileItemReader's setLinesToSkip method.
Upvotes: 3