BATCH-1395: Fixed reference to wrong ApplicationEvent
This commit is contained in:
@@ -38,6 +38,7 @@ import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -128,7 +129,7 @@ public class ClassPathXmlJobLoader implements ApplicationContextAware, Applicati
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
else if (event instanceof ContextRefreshedEvent) {
|
||||
else if (event instanceof ContextClosedEvent) {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.junit.Test;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.launch.NoSuchJobException;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -122,4 +124,35 @@ public class ClassPathXmlJobLoaderTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitCalledOnContextRefreshed() throws Exception {
|
||||
|
||||
Resource[] jobPaths = new Resource[] { new ClassPathResource(
|
||||
"org/springframework/batch/core/launch/support/2jobs.xml") };
|
||||
loader.setApplicationContext(new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/batch/core/launch/support/test-environment-with-registry-and-auto-register.xml"));
|
||||
loader.setJobPaths(jobPaths);
|
||||
GenericApplicationContext applicationContext = new GenericApplicationContext();
|
||||
applicationContext.refresh();
|
||||
loader.setApplicationContext(applicationContext);
|
||||
loader.onApplicationEvent(new ContextRefreshedEvent(applicationContext));
|
||||
assertEquals(2, registry.getJobNames().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDestroyCalledOnContextClosed() throws Exception {
|
||||
|
||||
Resource[] jobPaths = new Resource[] { new ClassPathResource(
|
||||
"org/springframework/batch/core/launch/support/2jobs.xml") };
|
||||
loader.setJobPaths(jobPaths);
|
||||
GenericApplicationContext applicationContext = new GenericApplicationContext();
|
||||
applicationContext.refresh();
|
||||
loader.setApplicationContext(applicationContext);
|
||||
loader.initialize();
|
||||
assertEquals(2, registry.getJobNames().size());
|
||||
loader.onApplicationEvent(new ContextClosedEvent(applicationContext));
|
||||
assertEquals(0, registry.getJobNames().size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user