Results 1 to 5 of 5

Thread: FlatFileItemWriter generating file even on exception

  1. #1
    Join Date
    Jan 2013
    Posts
    3

    Default FlatFileItemWriter generating file even on exception

    I am working on spring batch job that does the conventional READ > PROCESS > WRITE file operation.

    Below is the sample code of writer I am using.

    Code:
    <bean id="simBeqResponseFlatFileWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
            <property name="resource" ref="fileWriteSystemResource"></property>
            <property name="lineAggregator">
                <bean class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
            </property>
     </bean>
    The requirement is such that on any exception being thrown, the file should not be generated at all. I am facing a issue where even on some exception thrown in the code, a blank file is getting generated.

    Need some help in resolving the issue.

  2. #2
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    351

    Default

    You don't supply your step configuration here so it's hard to see what you are attempting to accomplish. Are you expecting that if an exception is thrown during the processing of any item in the step, the file should be deleted?
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  3. #3
    Join Date
    Jan 2013
    Posts
    3

    Default

    Quote Originally Posted by mminella View Post
    You don't supply your step configuration here so it's hard to see what you are attempting to accomplish. Are you expecting that if an exception is thrown during the processing of any item in the step, the file should be deleted?
    Yes, you are correct if an exception is thrown during the processing of any item in the step, the file should be deleted.
    In my case, the blank file is getting generated.

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

    Default

    On the FlatFileItemWriter, there is a flag, shouldDeleteIfEmpty that is set to false by default. By setting that to true, if no items are written to the file, it will be deleted once the step completes.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  5. #5
    Join Date
    Jan 2013
    Posts
    3

    Default

    Quote Originally Posted by mminella View Post
    On the FlatFileItemWriter, there is a flag, shouldDeleteIfEmpty that is set to false by default. By setting that to true, if no items are written to the file, it will be deleted once the step completes.
    Thanks Michael !!!

Tags for this Thread

Posting Permissions

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