Hi All,
I wanted to pass the multiple attributes from one step to another in a job.
I am able to pass a single variable or multiple attributes by adding code snippet in tasklet
ExecutionContext executionContext = stepExecution.getExecutionContext();
executionContext.put("someKey", "someValue");
executionContext.put("someKey1", "someValue1");
<bean id="promotionListener" class="org.springframework.batch.core.listener.Exe cutionContextPromotionListener" >
<property name="keys" value="someValue"/> // for single value
</bean>
<property name="keys" value="someValue,someValue1"/> // for mutliple values
Is there any way i can pass the excution context key values in the xml at the run time.
Thanks for your help.
Srikanth
Announcement
Announcement Module
Collapse
No announcement yet.
Passing multiple attributes between the steps in a job.
Page Title Module
Move
Remove
Collapse
X
-
Passing multiple attributes between the steps in a job.
Tags: None
-
I am not sure I fully understand what you a looking for but, if you need something more sophisticated than a simple list of keys to promote, you can implement your own StepExecutionListener (just write a class that implements StepExecutionListener). Then, in the afterStep() method, promote whatever you want. You can iterate over the entrySet() to find all the keys, or just promote specific keys.
Code:public ExitStatus afterStep(StepExecution stepExecution) { ExecutionContext stepContext = stepExecution.getExecutionContext(); ExecutionContext jobContext = stepExecution.getJobExecution().getExecutionContext(); ... return null; }
HTH
Leave a comment:
-
Hi Gary,
Sorry it was typo. your are correct that should be keynames
<property name="keys" value="someKey,someKey1"/>.
Is there anyway we can populate these key names in the xml at runtime, instead of specifying the keynames what we are going to use at compile time.
I mean if we are adding some attributes to stepExecution context like
ExecutionContext executionContext = stepExecution.getExecutionContext();
executionContext.put("someKey", "someValue");
executionContext.put("someKey1", "someValue1");
..
executionContext.put("someKeyn", "someValuen");
instead of putting the keys at compile time like
<property name="keys" value="someKey,someKey1,.. someKeyn"/>
can we populate the keynames in the value field in xml at runtime from stepExecutionContext object.
something like
<property name="keys" value="#{stepExecutionContext..........}"/>.
Hope I am able to explain the problem.
Thanks
Srikanth.
Leave a comment:
-
First of all, you need to supply the key, not the value, in the XML...
Code:<bean id="promotionListener" class="org.springframework.batch.core.listener.ExecutionContextPromotionListener" > <property name="keys" value="someKey"/> // for single value </bean>
Code:<bean id="promotionListener" class="org.springframework.batch.core.listener.ExecutionContextPromotionListener" > <property name="keys"> <list> <value>someKey</value> <value>someKey1</value> </list> </property> </bean>
When in doubt, just look at the JavaDoc for the property...
Code:/** * @param keys A list of keys corresponding to items in the {@link Step} * {@link ExecutionContext} that must be promoted. */ public void setKeys(String[] keys) { this.keys = keys; }
Last edited by Gary Russell; Jan 26th, 2011, 10:16 PM.
Leave a comment:
Leave a comment: