我在没有 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/