diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java index e0bd22ec5..b5e322d91 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java @@ -54,11 +54,12 @@ public class ExecutionContextPromotionListener extends StepExecutionListenerSupp if (PatternMatcher.match(statusPattern, exitCode)) { for (String key : keys) { if (stepContext.containsKey(key)) { + jobContext.put(key, stepContext.get(key)); + } else { if (strict) { throw new IllegalArgumentException("The key [" + key + "] was not found in the Step's ExecutionContext."); - } - jobContext.put(key, stepContext.get(key)); + } } } break; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java index 9b92ba69e..cf76e5b1d 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/ExecutionContextPromotionListenerTests.java @@ -66,6 +66,7 @@ public class ExecutionContextPromotionListenerTests { @Test public void promoteEntryStatusFound() throws Exception { ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener(); + listener.setStrict(true); JobExecution jobExecution = new JobExecution(1L); StepExecution stepExecution = jobExecution.createStepExecution("step1");