Announcement Announcement Module
Collapse
No announcement yet.
ClassifierCompositeItemWriter with multiple mathermap needs a itemWriter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ClassifierCompositeItemWriter with multiple mathermap needs a itemWriter

    Hi,
    Hi,
    I used ClassifierCompositeItemWriter for wirting into files based on the item grouping. Here I defined three item writers beans. Is there any other way to define one itemwriter bean, where I can append the map key along with the file name.

    say for example,
    1. read input file say input.txt
    2. Need to write the output files as output_111.txt,output_222.txt,.output_333.txt, based on the mapper key specified and with one itemwriter bean.

    In the below code I should have one itemWriter1 bean and able to write into three different files.

    Code:
    <bean id="customWriting"
    class="org.springframework.batch.item.support.ClassifierCompositeItemWriter">
    <property name="classifier">
    <bean class="org.springframework.batch.classify.BackToBackPatternClassifier">
        <property name="routerDelegate">
          <bean class="com.util.ItemGrouping" />
       </property>
     <property name="matcherMap">
        <map>
             <entry key="111*" value-ref="itemWriter1" />
             <entry key="222*" value-ref="itemWriter2" />
             <entry key="333*" value-ref="itemWriter3" />	        		
         </map>
    </property>
    </bean>
    </property>
    </bean>
    
    <bean id="itemWriter1" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
     <property name="lineAggregator" ref="lineAggregator" />
    <property name="resource" 	value="file:./output.csv"/>
    <property name="shouldDeleteIfExists" value="true" />
    </bean>
    
    <bean id="itemWriter2" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
    .....
    </bean>
    
    <bean id="itemWriter2" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
    .....
    </bean>
    
    <bean id="itemWriterDelegate" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
    .....
    </bean>
    Last edited by suresh.rpt; Jun 28th, 2011, 05:40 AM.

  • #2
    I am also facing the same problem. How did you go about it?

    Comment


    • #3
      Yes, I'd like to do the same also - is it possible to have just one itemWriter bean taking a parameter?

      Comment


      • #4
        In the nightly build version of Spring Batch, we have added the ability to mark an item "ResourceAware". By implementing that interface, it allows us to inject the resource the item came from for future reference within the step. Feel free to grab the nightly build code and give it a shot!

        Comment

        Working...
        X