java - Spring 批处理 : Tasklet without ItemWriter

标签 java spring spring-batch

我在没有 ItemWriter 的情况下定义了我的 tasklet :

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

我得到了这个错误:

配置问题:<b:chunk/>元素既没有 'writer' 属性也没有 <writer/>元素。

你有什么想法吗? 谢谢

最佳答案

好吧,在一个 block 中,读者和作者是强制性的!但是,ItemProcessor 是可选的。

这是来自官方文档:

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. In order to ease configuration, the Spring Batch namespace can be used:

<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.

writer - The ItemWriter that processes the items provided by the ItemReader.

transaction-manager - Spring's PlatformTransactionManager that will be used to begin and commit transactions during processing.

job-repository - The JobRepository that will be used to periodically store the StepExecution and ExecutionContext during processing (just before committing). For an in-line (one defined within a ) it is an attribute on the element; 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.

It should be noted that, job-repository defaults to "jobRepository" and transaction-manager defaults to "transactionManger". Furthermore, the ItemProcessor is optional, not required, since the item could be directly passed from the reader to the writer.

关于java - Spring 批处理 : Tasklet without ItemWriter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17191889/

相关文章:

java - 用Java构建一棵树

java - Hibernate 不删除/更新一对多

带有持久存储作业注册表的 spring batch 重新启 Action 业

java - Spring批处理FlatFileWriter并发问题

即使在 child 被保存后,Spring Data Jpa 测试也会返回空列表

数据列表中每个项目的 Spring Batch-Repeat 步骤

java - Jena 的 getLocalName 不使用 Turtle 返回数字本地名称

java - 更新 Java 类/play2 中的 View 参数

java - 打印为 Pdf...仅最后 2 页

java - 通过 gradle 为 spring boot 应用构建 docker 镜像时的最佳实践