Results 1 to 4 of 4

Thread: ClassifierCompositeItemWriter with multiple mathermap needs a itemWriter

  1. #1
    Join Date
    May 2011
    Posts
    15

    Default 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 at 04:40 AM.

  2. #2
    Join Date
    Jul 2011
    Posts
    6

    Default

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

  3. #3
    Join Date
    Feb 2011
    Posts
    19

    Default

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

  4. #4
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    366

    Default

    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!
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •