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

倖福魔咒の 提交于 2019-12-12 16:20:28

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/27066053/spring-batch-late-binding-of-commit-interval-not-working-with-skip-policy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!