简体   繁体   中英

spring batch : Tasklet without ItemWriter

I defined my tasklet without ItemWriter like this :

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

Do you have any idea ? Thanks

Well, in a chunk, A reader and a Writer are MANDATORY! however, The ItemProcessor is optional.

This is from the official doc :

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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