How to skip an exception in itemreader in spring batch?

Viewed 171

I am using spring batch application. I am reading from table and processing it. my code looks like below

@Bean
public XPath.Step step1(JdbcPagingItemReader<Customer> reader, ItemProcessor processor, ItemWriter writer) {
    return stepBuilderFactory.get("step1")
        .<Customer, CustomerConverted>chunk(5)
        .reader(reader)
        .processor(processor)
        .writer(writer)
        .faultTolerant()
        .skip(NullPointerException.class)
        .skipLimit(3)
        .listener(new SkipListener())
        .build();
}

@Bean
public JdbcPagingItemReader<Customer> reader() throws Exception {
    return new JdbcPagingItemReaderBuilder<Customer>()
        .dataSource(dataSource)
        .name("jdbcItemReader")
        .queryProvider(queryProvider())
        .rowMapper(CustomCustomerMapper)  //CustomCustomerMapper is a bean injected
        .pageSize(5)
        .saveState(false)
        .build();
}

In CustomCustomerMapper, I am simulating 1 NullPointerException per chunk. There is 1 skip listener invocation instead of 3 but Job status is completed.

My understanding is if in reader there is 1 exception per chunk, 3 chunk should get processed except the failing record and 4th chunk should fail as per above config.

But my app is not behaving like that. Guidance is appreciated.

0 Answers
Related