Spring Batch Javaconfig-将提交间隔也称为块大小参数化 [英] Spring Batch Javaconfig - parameterize commit-interval aka chunksize

查看:237
本文介绍了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

起因: org.springframework.expression.spel.SpelEvaluationException: EL1008E :(位置0):在以下位置找不到属性或字段'jobParameters' 类型的对象 'org.springframework.beans.factory.config.BeanExpressionContext'- 也许不公开?

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?

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

or - while using @StepScope for the step bean -

原因:java.lang.IllegalStateException:没有上下文持有者 可用于步骤范围

Caused by: java.lang.IllegalStateException: No context holder available for step scope

我知道我有一个工作的步进镜,其他步进镜的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-将提交间隔也称为块大小参数化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆