简体   繁体   English

spring batch:没有ItemWriter的Tasklet

[英]spring batch : Tasklet without ItemWriter

I defined my tasklet without ItemWriter like this : 我在没有ItemWriter的情况下定义了我的tasklet,如下所示:

<b:tasklet>
    <b:chunk reader="baseReader" processor="baseProcessor"  commit-interval="100" />
</b:tasklet>

and i got this error : 我收到了这个错误:

Configuration problem: The <b:chunk/> element has neither a 'writer' attribute nor a <writer/> element. 配置问题: <b:chunk/>元素既没有'writer'属性也没有<writer/>元素。

Do you have any idea ? 你有什么主意吗 ? Thanks 谢谢

Well, in a chunk, A reader and a Writer are MANDATORY! 嗯,在一大块,一个读者和一个作家是强制性的! however, The ItemProcessor is optional. 但是,ItemProcessor是可选的。

This is from the official doc : 这来自官方文件:

5.1.1. 5.1.1。 Configuring a Step 配置步骤

Despite the relatively short list of required dependencies for a Step, it is an extremely complex class that can potentially contain many collaborators. 尽管Step的必需依赖项列表相对较短,但它是一个非常复杂的类,可能包含许多协作者。 In order to ease configuration, the Spring Batch namespace can be used: 为了简化配置,可以使用Spring Batch命名空间:

<job id="sampleJob" job-repository="jobRepository">
<step id="step1">
    <tasklet transaction-manager="transactionManager">
        <chunk reader="itemReader" writer="itemWriter" commit-interval="10"/>
    </tasklet>
</step>

The configuration above represents the only required dependencies to create a item-oriented step: 上面的配置表示创建面向项目的步骤所需的唯一依赖项:

reader - The ItemReader that provides items for processing. reader - 提供处理项目的ItemReader。

writer - The ItemWriter that processes the items provided by the ItemReader. writer - 处理ItemReader提供的项目的ItemWriter。

transaction-manager - Spring's PlatformTransactionManager that will be used to begin and commit transactions during processing. transaction-manager - Spring的PlatformTransactionManager,用于在处理过程中开始和提交事务。

job-repository - The JobRepository that will be used to periodically store the StepExecution and ExecutionContext during processing (just before committing). job-repository - 将在处理期间(就在提交之前)定期存储StepExecution和ExecutionContext的JobRepository。 For an in-line (one defined within a ) it is an attribute on the element; 对于内联(在a中定义的内容),它是元素的属性; for a standalone step, it is defined as an attribute of the . 对于独立步骤,它被定义为的属性。

commit-interval - The number of items that will be processed before the transaction is committed. commit-interval - 提交事务之前将处理的项目数。

It should be noted that, job-repository defaults to "jobRepository" and transaction-manager defaults to "transactionManger". 应该注意的是,job-repository默认为“jobRepository”,而transaction-manager默认为“transactionManger”。 Furthermore, the ItemProcessor is optional, not required, since the item could be directly passed from the reader to the writer. 此外,ItemProcessor是可选的,不是必需的,因为该项可以直接从阅读器传递给编写器。

We can define a chunk without writer (just a reader + processor), i managed to do so. 我们可以定义一个没有编写器的块(只是一个读取器+处理器),我设法这样做。 It seems that in order to pass the writer step containing the chunk must inherit abstract step parents, like this : 似乎为了传递包含块的编写器步骤必须继承抽象步骤父类,如下所示:

    <b:step id="task" parent="Task">
        <b:tasklet>
            <b:chunk reader="baseReader" processor="baseProcessor" commit- interval="100" />
        </b:tasklet>
    </b:step>

    <b:job id="batch" parent="Batch">
        <b:step id="etape" parent="task" />
    </b:job>

Problem solved, thanks! 问题解决了,谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM