diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClassPathXmlApplicationContextJobFactory.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClassPathXmlApplicationContextJobFactory.java index b7b95f4e2..4741ba752 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClassPathXmlApplicationContextJobFactory.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/ClassPathXmlApplicationContextJobFactory.java @@ -21,7 +21,9 @@ import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobExecutionException; import org.springframework.batch.core.configuration.JobFactory; +import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -32,13 +34,30 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * @author Dave Syer * */ -public class ClassPathXmlApplicationContextJobFactory implements JobFactory { +public class ClassPathXmlApplicationContextJobFactory implements JobFactory, ApplicationContextAware { final private String beanName; final private String path; - final private ApplicationContext parent; + private ApplicationContext parent; + + /** + * Setter for the parent application context. + * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) + */ + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + parent = applicationContext; + } + + /** + * @param beanName the id of the {@link Job} in the application context to + * be created + * @param path the path to the XML configuration containing the {@link Job} + */ + public ClassPathXmlApplicationContextJobFactory(String beanName, String path) { + this(beanName, path, null); + } /** * @param beanName the id of the {@link Job} in the application context to diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ClassPathXmlApplicationContextJobFactoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ClassPathXmlApplicationContextJobFactoryTests.java index d7ed20b6a..ddbd02469 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ClassPathXmlApplicationContextJobFactoryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/support/ClassPathXmlApplicationContextJobFactoryTests.java @@ -25,7 +25,7 @@ import org.springframework.util.ClassUtils; */ public class ClassPathXmlApplicationContextJobFactoryTests extends TestCase { - private ClassPathXmlApplicationContextJobFactory factory = new ClassPathXmlApplicationContextJobFactory("test-job", ClassUtils.addResourcePathToPackagePath(getClass(), "trivial-context.xml"), null); + private ClassPathXmlApplicationContextJobFactory factory = new ClassPathXmlApplicationContextJobFactory("test-job", ClassUtils.addResourcePathToPackagePath(getClass(), "trivial-context.xml")); /** * Test method for {@link org.springframework.batch.core.configuration.support.ClassPathXmlApplicationContextJobFactory#createJob()}.