Spring Package - late binding of commit interval not working with skip policy
I am trying to use the latest commit-interval attribute binding for a block.
When a chunk does not contain a skip policy or a retry policy, it works fine, but as soon as a skip policy (or even a retry policy) is added, the commit interval is not counted and the package behaves as if the commit interval is set to 1. It's strange when the interval is fixed. hardcoded, it works great ...
So this configuration works fine:
<chunk reader="multiAccuseReceptionItemReader"
processor="enrichissementPrescriptionItemProcessor"
writer="prescriptionItemWriter"
commit-interval="#{jobExecutionContext['commits']}">
This works great too:
<chunk reader="multiAccuseReceptionItemReader"
processor="enrichissementPrescriptionItemProcessor"
writer="prescriptionItemWriter"
skip-policy="skipPolicy"
commit-interval="3">
But this ignores the commit interval and sets it to 1:
<chunk reader="multiAccuseReceptionItemReader"
processor="enrichissementPrescriptionItemProcessor"
writer="prescriptionItemWriter"
skip-policy="skipPolicy"
commit-interval="#{jobExecutionContext['commits']}">
I tried to use the completion policy with 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 counted, even if it's hardcoded. Without any skip policy or retry policy, the chunkSize (hardcoded or late binding) is respected.
I am using Spring Batch 2.2.0 (and cannot change).
Why is this behavior? How can I dynamically set the commit interval using skip policy and retry policy?
source to share
This is a known spring-batch bug from the org.springframework.batch.core.configuration.xml.StepParserStepFactoryBean class: https://jira.spring.io/browse/BATCH-2096 .
It has been fixed in version 2.2.2.
So, the best solution is to migrate to v2.2.2 from spring-batch (which is the same as 2.2.0 with some bug fixes).
If for example I really can't update, your best bet is to copy the org.springframework.batch.core.configuration.xml.StepParserStepFactoryBean class from git (tag 2.2.2) , add it to your sources and make sure your sources are loaded before spring -batch-core jar on your classpath.
source to share