Fixed leaking of Job level properties into the StepContext

This commit is contained in:
Michael Minella
2013-08-16 11:19:48 -05:00
parent 656ca5855d
commit 960166510e
3 changed files with 21 additions and 3 deletions

View File

@@ -40,7 +40,7 @@ public class StepContextFactoryBean implements FactoryBean<StepContext> {
@Override
public StepContext getObject() throws Exception {
org.springframework.batch.core.StepExecution stepExecution = StepSynchronizationManager.getContext().getStepExecution();
Properties properties = batchPropertyContext.getBatchProperties(stepExecution.getStepName());
Properties properties = batchPropertyContext.getStepLevelProperties(stepExecution.getStepName());
return new StepContext(stepExecution, properties);
}

View File

@@ -61,6 +61,24 @@ public class BatchPropertyContext {
}
}
public Properties getStepLevelProperties(String beanName) {
Properties properties = new Properties();
if (batchProperties.containsKey(beanName)) {
properties.putAll(batchProperties.get(beanName));
} else {
if(beanName.startsWith("scopedTarget")) {
beanName = beanName.substring(13);
}
if(batchProperties.containsKey(beanName)) {
properties.putAll(batchProperties.get(beanName));
}
}
return properties;
}
/**
* <p>
* Obtains the batch {@link Properties} for the provided bean name / batch artifact. The returned

View File

@@ -491,8 +491,8 @@ public class JobPropertyTests {
org.springframework.util.Assert.isNull(stepContext.getProperties().get("step1PropertyName2"));
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step2PropertyName1").equals("step2PropertyValue1"));
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("step2PropertyName2").equals("step2PropertyValue2"));
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1").equals("jobPropertyValue1"));
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2").equals("jobPropertyValue2"));
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName1") == null);
org.springframework.util.Assert.isTrue(stepContext.getProperties().get("jobPropertyName2") == null);
return null;
}