Announcement Announcement Module
No announcement yet.
Question about CompositeItemWriter and the need to register streams Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question about CompositeItemWriter and the need to register streams

    Hi, I'm new to Spring Batch and I'm currently studying its documentation and samples. I have a question on the CompositeItemWriter. The documentation, the examples and the advices I find on the Internet say that the delegate streams must be registered on their own, like this:

        <job id="compositeItemWriterJob" xmlns="" >
            <step id="step1">
                    <chunk reader="fileItemReader" processor="processor" writer="compositeWriter"
                            <stream ref="fileItemReader"/>
                            <stream ref="fileItemWriter1"/>
                            <stream ref="fileItemWriter2"/>
        <bean id="compositeWriter" class="">
            <property name="delegates">
                    <bean class="">
                        <property name="dao" ref="tradeDao" />
                    <ref bean="fileItemWriter1" />
                    <ref bean="fileItemWriter2" />
    Now, apart from the fact that this example (taken from compositeItemWriterSampleJob.xml in spring-batch-samples) also registers the fileItemReader, which should not be necessary (since it's directly referenced by the tasklet definition), I was wondering why it should be necessary to register fileItemWriter1 and fileItemWriter2 either.
    In fact, since BATCH-836, CompositeItemWriter implements the ItemStream interface and, unless the property ignoreItemStream is true (the default is false), it also takes care of opening and closing its delegates if they are ItemStreams on their own.

    So, the question is: is it still a requirement to register the delegate ItemStreams of a CompositeItemStream independently? And, if so, why?

  • #2
    If you're using a version recent enough, you are correct and you shouldn't need to register the ItemWriters independently.


    • #3
      Oh yes, thank you Michael. For the records the documentation issue has been fixed with