Announcement Announcement Module
Collapse
No announcement yet.
How do I get ref to JobExecution in ItemWriteListener's afterWrite method? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I get ref to JobExecution in ItemWriteListener's afterWrite method?

    The signature of org.springframework.batch.core.ItemWriteListener's afterWrite method only takes List<T>, where T is your item type. Inside my implementation of this method, I need to get a reference to the current JobExecution. How do I do that?

    Thanks,
    Matthew

  • #2
    Make the ItemWriter class implement StepExecutionListener interface. There you will have 2 methods : beforeStep() and afterStep(). In before step, store the reference of StepExecutionListener in the class variable. And then, when write() is called, use appropriate getter method on stepExecutionListener (the one stored in class variable) to get hold of JobExecutionContext.


    There is a catch here, if you have declared your writer to have the scope as step, then this will not work. (At least, that is what I have experienced!!!)

    Comment


    • #3
      Actually, I **had** to make the scope "step" and everything is working jim dandy. Thanks!

      Comment


      • #4
        Is it?? hmmm... Possible to share the snippet of config? cause I was not able to get old of stepexecutionlistener when scope is step

        Comment

        Working...
        X