diff --git a/execution/src/main/java/org/springframework/batch/execution/step/SimpleStepExecutorFactory.java b/execution/src/main/java/org/springframework/batch/execution/step/SimpleStepExecutorFactory.java index 27df2be31..e33da04f2 100644 --- a/execution/src/main/java/org/springframework/batch/execution/step/SimpleStepExecutorFactory.java +++ b/execution/src/main/java/org/springframework/batch/execution/step/SimpleStepExecutorFactory.java @@ -23,6 +23,7 @@ import org.springframework.batch.execution.step.simple.SimpleStepExecutor; import org.springframework.batch.repeat.RepeatOperations; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatTemplate; +import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; /** @@ -32,7 +33,7 @@ import org.springframework.util.Assert; * @author Dave Syer * */ -public class SimpleStepExecutorFactory implements StepExecutorFactory { +public class SimpleStepExecutorFactory implements StepExecutorFactory, InitializingBean { private JobRepository jobRepository; @@ -70,8 +71,21 @@ public class SimpleStepExecutorFactory implements StepExecutorFactory { } + /** + * Public setter for {@link JobRepository}. + * + * @param jobRepository is a mandatory dependence (no default). + */ public void setJobRepository(JobRepository jobRepository) { this.jobRepository = jobRepository; } + /** + * Assert that all mandatory properties are set (the {@link JobRepository}). + * + * @throws Exception + */ + public void afterPropertiesSet() throws Exception { + Assert.notNull(jobRepository); + } } diff --git a/execution/src/test/java/org/springframework/batch/execution/step/SimpleStepExecutorFactoryTests.java b/execution/src/test/java/org/springframework/batch/execution/step/SimpleStepExecutorFactoryTests.java index 229116113..09f621138 100644 --- a/execution/src/test/java/org/springframework/batch/execution/step/SimpleStepExecutorFactoryTests.java +++ b/execution/src/test/java/org/springframework/batch/execution/step/SimpleStepExecutorFactoryTests.java @@ -62,4 +62,14 @@ public class SimpleStepExecutorFactoryTests extends TestCase { "JobRepository") >= 0); } } + + public void testMandatoryProperties() throws Exception { + factory = new SimpleStepExecutorFactory(); + try { + factory.afterPropertiesSet(); + fail("Expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // expected + } + } }