Spring Batch Javaconfig - parameterize commit-interval aka chunksize

試著忘記壹切 提交于 2019-12-01 10:31:40

Adding @JobScope annotation to Step definition is working in Spring Batch 3:

@Bean
@JobScope
public Step step(
        ItemStreamReader<Map<String, Object>> reader,
        ItemWriter<Map<String, Object>> writer,
        @Value("#{jobParameters['commit.interval']}") Integer commitInterval
)

This will initialize the step bean at job execution, so late binding of jobParameters is working in this case.

I have poor confidence with JavaConfig and - maybe - this can be an issue only for commit-interval during late binding for java configuration (in SB ChunkElementParser.java source there are few lines of code that checks for commit-interval starts with a # and inject a SimpleCompletionPolicy step scoped); you can try injecting a StepExecutionSimpleCompletionPolicy and check if this solution works.

Also, I have never tried late binding commit-interval with xml config but there is a [opened ticket with title Commit Interval not working as intended when used in Late Binding

As last chance, if you are using version 3.0, you can also annotate step with @JobScope and check if this solution works.

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