Results 1 to 3 of 3

Thread: Conditional Step execution

  1. #1

    Default Conditional Step execution

    I have a job with e.g. steps 1 to 10 in a sequnetial execution.

    Based on a JobParameter (mmExport=true) enterd on the command line I want to either execute all the steps or END after e.g step 6.

    I looked at using a Decider but that won't work becuase it is not inside a step so I can't give it a scope="step"
    but I need a scope="step" in order to do something like
    <bean id="deciderMM" class="de.quirin.siron.job.MMDecider" scope="step">
    <property name="exportMM" value="#{jobParameters['export.mm']}"/>
    </bean>

    Is there any elegant way to do this in Spring Batch?

  2. #2
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    351

    Default

    You are correct that the decision construct is not executed within the scope of a step so using the step scope is of no use here (that actually sounds like a good opportunity for refactoring). That being said, you could use a tasklet step to inject your property and either end or next based on that value. While not quite as elegant as you were looking for, it's the best we have right now.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  3. #3

    Default

    Yes I already did what you suggested but it's not really elegant to have to add a Tasklet to make the decision.

    Giving the Decider a scope of "step" would definitely be a good idea. But maybe an alternative would be to add something like
    <end if="#{!jobParameters['export.mm']}"/> might make it easier to control long sequences of steps based on command line parameters and removes the need for a Decider.

Tags for this Thread

Posting Permissions

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