Jean Peupluh
Jean Peupluh

Reputation: 81

Spring Batch - late binding of commit interval not working with skip policy

I'm trying to use the late binding on the commit-interval attribute of a chunk.

When the chunk doesn't contain a skip-policy or retry-policy, it works fine but as soon as a skip-policy is added (or even a retry-policy), the commit-interval is not taken into account and the batch works as if the commit-interval is set to 1. The weird thing is, when the commit-interval is hard coded, it works fine...

So this configuration works fine :

<chunk reader="multiAccuseReceptionItemReader" 
                   processor="enrichissementPrescriptionItemProcessor"
                   writer="prescriptionItemWriter" 
                   commit-interval="#{jobExecutionContext['commits']}">

This one works fine also :

<chunk reader="multiAccuseReceptionItemReader" 
                   processor="enrichissementPrescriptionItemProcessor"
                   writer="prescriptionItemWriter"
                   skip-policy="skipPolicy"
                   commit-interval="3">

But this one doesn't take into account the commit-interval and set it to 1 :

<chunk reader="multiAccuseReceptionItemReader" 
                   processor="enrichissementPrescriptionItemProcessor"
                   writer="prescriptionItemWriter"
                   skip-policy="skipPolicy"
                   commit-interval="#{jobExecutionContext['commits']}">

I tried to use completion-policy with the simpleCompletionPolicy instead of the commit-interval, but it's even worse : when there is a skip-policy or a retry-policy, the chunkSize is not taken into account, even if it is hard coded. Without any skip-policy or retry-policy the chunkSize is taken into account (hard coded or late binding).

I'm using Spring Batch 2.2.0 (and can't change).

Why this behavior? How can I dynamically set the commit-interval with a skip-policy and a retry-policy?

Upvotes: 3

Views: 1774

Answers (1)

Jean Peupluh
Jean Peupluh

Reputation: 81

It's a known bug of spring-batch from the class org.springframework.batch.core.configuration.xml.StepParserStepFactoryBean : https://jira.spring.io/browse/BATCH-2096.

It has been corrected in version 2.2.2.

So the best solution is to upgrade to v2.2.2 of spring-batch (which is the same as 2.2.0 with some bug corrections).

If -like me- you really can't upgrade, then the best way is to copy the class org.springframework.batch.core.configuration.xml.StepParserStepFactoryBean from git (tag 2.2.2), add it to your sources and make sure that your sources are loaded before spring-batch-core jar in your classpath.

Upvotes: 2

Related Questions