Reputation: 141
I want to process something after commit on spring batch
.
And I tried this example (https://dzone.com/articles/transaction-synchronization-and-spring-application).
That example works perfectly on springboot
like this flow.
1. some update query and event publish by ApplicationEventPublisher
2. some update query and event publish by ApplicationEventPublisher
3. some update query and event publish by ApplicationEventPublisher
4. commit
5. after commit logic I maked
6. after commit logic I maked
7. after commit logic I maked
But on spring batch
not work as expected.
1. some update query and event publish by ApplicationEventPublisher, and after commit logic
2. some update query and event publish by ApplicationEventPublisher, and after commit logic
3. some update query and event publish by ApplicationEventPublisher, and after commit logic
3. commit
I doubt @TransactionalEventListener
or ApplicationEventPublisher
doesn't work on spring batch.
Is any difference spring context between springboot
and spring batch
??
Or for @TransactionalEventListener
, Is any setting on spring batch
??
Upvotes: 1
Views: 1094
Reputation: 31650
- some update query and event publish by ApplicationEventPublisher
Spring Batch does not intercept those events. You need to make your listener participate in one of the step lifecycle events (before/after read, before/after write, etc)
I want to process something after commit on spring batch.
You can use a ChunkListener#afterChunk
for that, which is called after the transaction is committed.
Upvotes: 3