Andres Felipe
Andres Felipe

Reputation: 684

Spring Batch custom ItemReader won't open

I have a Spring Batch project where I have JsonResouurceAsyncPagingItemReader, a custom ItemReader which asynchronously retrieves data from a web service.

This custom ItemReader uses a ExecutorService to submit calls to the web service. However I am having trouble to initialize it.

I tried to initialize it through the doOpen method provided by AbstractItemCountingItemStreamItemReader, however seems doOpen it's not being called.

The ItemReader is being injected by Spring in this way:

@Bean
@JobScope
public ItemReader<Map<String, Object>> reader(@Value("#{jobParameters['lastRun']}") Date lastRun,
        @Value("#{jobParameters['codInt']}") Long codInt) {

    Map<String, Object> parameterValues = new HashMap<String, Object>();
    if (lastRun != null) {
        parameterValues.put("lastRun", DateFormatUtils.format(lastRun, dateFormat));
    }
    if (codInt != null) {
        parameterValues.put("codInt", codInt);
    }

    JsonResourceAsyncPagingItemReader<Map<String, Object>> reader = new JsonResourceAsyncPagingItemReader<>();
    reader.setHttpUrl(server + pathTemplate);
    reader.setRestTemplate(restTemplate);
    reader.setParameterValues(parameterValues);
    reader.setPageSize(pageSize);

    return reader;
}

And further used in a Step like this:

@Bean
public Step importProductStep() {
    return stepBuilderFactory.get("importProductJobStep")
            .<Map<String, Object>, Product>chunk(1000)
            .reader(reader(null, null))
            .processor(processor())
            .writer(writer())
            .build();
}

Any idea on what could be wrong?

Upvotes: 0

Views: 1528

Answers (1)

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18383

If you return an ItemStream, or an ItemStreamWriter, it would should fine.
(Look at this ticket)

Upvotes: 5

Related Questions