diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java index 76080a15a..00c7e8ca5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java @@ -71,6 +71,12 @@ public class FlowJob extends AbstractJob { if (state instanceof StepHolder) { return ((StepHolder) state).getStep(); } + // The state names can be prefixed with the job name for + // uniqueness... + state = this.flow.getState(getName()+"."+stepName); + if (state instanceof StepHolder) { + return ((StepHolder) state).getStep(); + } return null; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java index 50454b431..706be10d6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java @@ -518,6 +518,23 @@ public class FlowJobTests { assertEquals("step2", step.getName()); } + @Test + public void testGetStepExistsWithPrefix() throws Exception { + SimpleFlow flow = new SimpleFlow("job"); + List transitions = new ArrayList(); + transitions.add(StateTransition.createStateTransition(new StepState("job.step", new StubStep("step")), "end0")); + transitions.add(StateTransition.createEndStateTransition(new EndState(FlowExecutionStatus.COMPLETED, "end0"))); + flow.setStateTransitions(transitions); + flow.afterPropertiesSet(); + job.setFlow(flow); + job.setName(flow.getName()); + job.afterPropertiesSet(); + + Step step = job.getStep("step"); + assertNotNull(step); + assertEquals("step", step.getName()); + } + @Test public void testGetStepNotExists() throws Exception { SimpleFlow flow = new SimpleFlow("job");