Announcement Announcement Module
Collapse
No announcement yet.
Question about CompositeItemWriter and the need to register streams Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    Code:
        <job id="compositeItemWriterJob" xmlns="http://www.springframework.org/schema/batch" >
            <step id="step1">
                <tasklet>
                    <chunk reader="fileItemReader" processor="processor" writer="compositeWriter"
                           commit-interval="1">
                        <streams>
                            <stream ref="fileItemReader"/>
                            <stream ref="fileItemWriter1"/>
                            <stream ref="fileItemWriter2"/>
                        </streams>
                    </chunk>
                </tasklet>
            </step>
        </job>
    
        <bean id="compositeWriter" class="org.springframework.batch.item.support.CompositeItemWriter">
            <property name="delegates">
                <list>
                    <bean class="org.springframework.batch.sample.domain.trade.internal.TradeWriter">
                        <property name="dao" ref="tradeDao" />
                    </bean>
                    <ref bean="fileItemWriter1" />
                    <ref bean="fileItemWriter2" />
                </list>
            </property>
        </bean>
    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.

    Comment


    • #3
      Oh yes, thank you Michael. For the records the documentation issue has been fixed with https://jira.spring.io/browse/BATCH-2180.

      Comment

      Working...
      X