Announcement Announcement Module
Collapse
No announcement yet.
Spring batch 2 pass object between step Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      http://static.springsource.org/sprin...aToFutureSteps

      Comment


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

        Comment


        • #5
          Wow you have useful code... Thanks for information...
          Forex Megadroid

          Comment


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

            Comment


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

              Comment


              • #8
                Hi,

                could you provide the full example code please?

                Comment


                • #9
                  Don't.
                  Thread is 2 years old.

                  Comment

                  Working...
                  X