Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 552
Yassine EL AYACHI Avatar asked Apr 08 '26 18:04

Yassine EL AYACHI


2 Answers

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.

like image 179
Cygnusx1 Avatar answered Apr 11 '26 07:04

Cygnusx1


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!

like image 35
Yassine EL AYACHI Avatar answered Apr 11 '26 06:04

Yassine EL AYACHI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!