Package org.springframework.batch.core
Interface ItemWriteListener<S>
- All Superinterfaces:
StepListener
- All Known Implementing Classes:
CompositeItemWriteListener
,DefaultItemFailureHandler
,ItemListenerSupport
,MulticasterBatchListener
,StepListenerSupport
Listener interface for the writing of items. Implementations of this interface are notified before, after, and in case of any exception thrown while writing a chunk of items.
Note: This listener is designed to work around the lifecycle of an item. This means that each method should be called once within the lifecycle of an item and that, in fault-tolerant scenarios, any transactional work that is done in one of these methods is rolled back and not re-applied. Because of this, it is recommended to not perform any logic that participates in a transaction when using this listener.
- Author:
- Lucas Ward, Mahmoud Ben Hassine
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
afterWrite
(Chunk<? extends S> items) Called afterItemWriter.write(Chunk)
.default void
beforeWrite
(Chunk<? extends S> items) Called beforeItemWriter.write(Chunk)
default void
onWriteError
(Exception exception, Chunk<? extends S> items) Called if an error occurs while trying to write.
-
Method Details
-
beforeWrite
Called beforeItemWriter.write(Chunk)
- Parameters:
items
- to be written
-
afterWrite
Called afterItemWriter.write(Chunk)
. This is called before any transaction is committed, and beforeChunkListener.afterChunk(ChunkContext)
.- Parameters:
items
- written items
-
onWriteError
Called if an error occurs while trying to write. Called inside a transaction, but the transaction will normally be rolled back. There is no way to identify from this callback which of the items (if any) caused the error.- Parameters:
exception
- thrown fromItemWriter
items
- attempted to be written.
-