waffledood
waffledood

Reputation: 283

Spring Batch - Promoting multiple pieces of data with ExecutionContextPromotionListener

I have a Spring Batch project where I will need to save 2 keys in the Step ExecutionContext, which will be promoted to the Job ExecutionContext.

I understand from online examples, e.g. this code where you can set multiple keys.

This example is done using Java, where the ExecutionContextPromotionListener is defined as a Java class. In my case, it's defined in an XML file

Here's the current XML configuration for the promotion listener:

    <bean id="promotionListener" class="org.springframework.batch.core.listener.ExecutionContextPromotionListener">
        <property name="keys" value="idA"/>
    </bean>

But i now need another key to be in the ExecutionContext.

Is this how i define it?

    <bean id="promotionListener" class="org.springframework.batch.core.listener.ExecutionContextPromotionListener">
        <property name="keys">
            <list>
                <value>idA</value>
                <value>idB</value>
            </list>
        </property>
    </bean>

This doesn't work, so i tried the following but didn't work as the compiler gave an error:

        <property name="keys" values="idA,idB"/>

This doesn't work either

        <property name="keys" value="idA,idB"/>

I couldn't get any online references, even on StackOverflow, for what i'm trying to implement

Appreciate any help, thanks in advance


Follow-up questions:

  1. Can i use the same promotionListener bean in multiple steps?
  2. With regards to Q1, i want to have the promotionListener bean have a String array of keys, one is idA, another is idB. Can i have Step X save data using idA & Step Z save data using idB, where both Step X & Z have promotionListener as the listeners. Is this allowed? Or should I use 2 separate promotionListeners: promotionListener1 & promotionListener2 for each of the Steps?

Upvotes: 0

Views: 419

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31730

The keys field in ExecutionContextPromotionListener is of type String[]. So you need to define the keys as an array. This should help: How to define a bean of String array in Spring (using XML configuration)

Upvotes: 1

Related Questions