Fixed leaking of Job level properties into the StepContext
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user