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:
- Can i use the same
promotionListenerbean in multiple steps? - With regards to Q1, i want to have the
promotionListenerbean have aStringarray of keys, one isidA, another isidB. Can i have Step X save data usingidA& Step Z save data usingidB, where both Step X & Z havepromotionListeneras the listeners. Is this allowed? Or should I use 2 separatepromotionListeners:promotionListener1&promotionListener2for each of theSteps?
The
keysfield inExecutionContextPromotionListeneris of typeString[]. 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)