Results 1 to 9 of 9

Thread: Spring batch 2 pass object between step

  1. #1
    Join Date
    Aug 2009
    Posts
    1

    Default Spring batch 2 pass object between step

    Hi Everyone,
    Currently I have a problem with my code, I am trying to pass object between steps. is that possible to do that ? I try to use JobExecutionContext but have exception when running my job.


    Thank you

  2. #2
    Join Date
    Aug 2009
    Posts
    4

    Default

    My workaround for this is by retrieving reference to JobExecution, then put the object on its ExecutionContext.
    But it seem long way just to pass object between step, is there any other shorter path perhaps?

    regards

  3. #3
    Join Date
    Feb 2008
    Posts
    488

  4. #4

    Default

    Hello DHGarrette,

    I followed the instruction in the link. I'm using Spring Batch 2.0.0, though this version supports Annotations the @AfterStep and @BeforeStep annotations did not work (i.e. not invoked by Spring Batch container). To overcome this I did following.

    Step 1: Implemented
    Code:
    StepExecutionListener
    interface both the Tasklets (i.e. step1 tasklet and step2 tasklet)
    Step 2: I set the value to be passed to next step In
    Code:
    afterStep(StepExecution)
    method as follows
    Code:
    stepExecution.getJobExecution().getExecutionContext().put("key", anyObject);
    Step 3: To read the value from step2 tasklet follow the below simple code in
    Code:
    beforeStep(StepExecution)
    Code:
    stepExecution.getJobExecution().getExecutionContext().get("key");
    Though the above steps help me to pass objects between Steps, could you please tell me what might cause the Annotations @BeforeStep and @AfterStep to not work?

  5. #5

    Default

    Wow you have useful code... Thanks for information...
    Forex Megadroid

  6. #6
    Join Date
    Feb 2008
    Posts
    488

    Default

    Did you register the annotated objects using the <listeners/> tag in the xml?

  7. #7

    Default

    DHGarrette,

    No, I did not add the annotated objects in listeners tag. Once I added the annotated object in listeners tag it started working. Thanks for the tip!

  8. #8
    Join Date
    Jul 2012
    Posts
    24

    Default

    Hi,

    could you provide the full example code please?

  9. #9

    Default

    Don't.
    Thread is 2 years old.

Posting Permissions

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