Announcement Announcement Module
Collapse
No announcement yet.
FlatFileItemWriter generating file even on exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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?

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment


        • #5
          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 !!!

          Comment

          Working...
          X