本文介绍了Spring Batch Javaconfig-将提交间隔也称为块大小参数化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用基于Spring Batch xml的配置,您可以像下面这样参数化commit-interval/chunk大小:

with Spring Batch xml based configuration you can parameterize the commit-interval / chunk size like:

<job id="basicSimpleJob"
     xmlns="http://www.springframework.org/schema/batch">
    <step id="basicSimpleStep" >
        <tasklet>
            <chunk
                reader="reader"
                processor="processor"
                writer="writer"
                commit-interval="#{jobParameters['commit.interval']}">
            </chunk>
        </tasklet>
    </step>
</job>

使用基于javaconfig的配置,它可以看起来像

with javaconfig based configuration it could look like

@Bean
public Step step(
        ItemStreamReader<Map<String, Object>> reader,
        ItemWriter<Map<String, Object>> writer,
        @Value("#{jobParameters['commit.interval']}") Integer commitInterval
) throws Exception {
    return steps
            .get("basicSimpleStep")
            .<Map<String, Object>, Map<String, Object>>chunk(commitInterval)
            .reader(reader)
            .processor(new FilterItemProcessor())
            .writer(writer)
            .build();
}

但它不起作用,我也可以

but it does not work, i get either

或-在对步豆使用@StepScope时-

or - while using @StepScope for the step bean -

我知道我有一个工作的步进镜,其他步进镜的Bean也可以工作(在与step相同的类中定义)

i know i have a working stepscope, other stepscoped beans work(defined inside same class as step)

现在我使用了与stepScope一起使用的CompletionPolicy,但我想知道是否有人以正常"方式工作或是否应该购买JIRA机票

right now i use a CompletionPolicy which does work with stepScope but i would like to know if someone got it to work the "normal" way or if it's time for a JIRA ticket

... -2263

... which is created at https://jira.spring.io/browse/BATCH-2263

推荐答案

在Spring Batch 3中可以将@JobScope批注添加到Step定义中.

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
)

这将在作业执行时初始化step Bean,因此在这种情况下可以进行jobParameters的后期绑定.

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

这篇关于Spring Batch Javaconfig-将提交间隔也称为块大小参数化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:44