Prefer explicit "org.quartz.scheduler.instanceName" over bean name

Issue: SPR-16884
This commit is contained in:
Juergen Hoeller
2018-09-19 22:19:28 +02:00
parent a6f9c4c599
commit 50c9542796
3 changed files with 68 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -292,10 +292,7 @@ public class QuartzSupportTests {
bean.destroy();
}
/**
* Tests the creation of multiple schedulers (SPR-772)
*/
@Test
@Test // SPR-772
public void multipleSchedulers() throws Exception {
ClassPathXmlApplicationContext ctx = context("multipleSchedulers.xml");
try {
@@ -310,6 +307,21 @@ public class QuartzSupportTests {
}
}
@Test // SPR-16884
public void multipleSchedulersWithQuartzProperties() throws Exception {
ClassPathXmlApplicationContext ctx = context("multipleSchedulersWithQuartzProperties.xml");
try {
Scheduler scheduler1 = (Scheduler) ctx.getBean("scheduler1");
Scheduler scheduler2 = (Scheduler) ctx.getBean("scheduler2");
assertNotSame(scheduler1, scheduler2);
assertEquals("quartz1", scheduler1.getSchedulerName());
assertEquals("quartz2", scheduler2.getSchedulerName());
}
finally {
ctx.close();
}
}
@Test
public void twoAnonymousMethodInvokingJobDetailFactoryBeans() throws Exception {
Assume.group(TestGroup.PERFORMANCE);
@@ -363,8 +375,8 @@ public class QuartzSupportTests {
@SuppressWarnings("resource")
public void schedulerAutoStartupFalse() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(
SchedulerFactoryBean.class).addPropertyValue("autoStartup", false).getBeanDefinition();
BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(SchedulerFactoryBean.class)
.addPropertyValue("autoStartup", false).getBeanDefinition();
context.registerBeanDefinition("scheduler", beanDefinition);
Scheduler bean = context.getBean("scheduler", Scheduler.class);
assertFalse(bean.isStarted());

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="scheduler1" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">quartz1</prop>
</props>
</property>
</bean>
<bean id="scheduler2" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">quartz2</prop>
</props>
</property>
</bean>
</beans>