Prefer explicit "org.quartz.scheduler.instanceName" over bean name
Issue: SPR-16884
This commit is contained in:
@@ -192,9 +192,6 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
|
||||
@Nullable
|
||||
private Map<String, ?> schedulerContextMap;
|
||||
|
||||
@Nullable
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Nullable
|
||||
private String applicationContextSchedulerContextKey;
|
||||
|
||||
@@ -213,6 +210,12 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
|
||||
|
||||
private boolean waitForJobsToCompleteOnShutdown = false;
|
||||
|
||||
@Nullable
|
||||
private String beanName;
|
||||
|
||||
@Nullable
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Nullable
|
||||
private Scheduler scheduler;
|
||||
|
||||
@@ -252,9 +255,13 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the Scheduler to create via the SchedulerFactory.
|
||||
* <p>If not specified, the bean name will be used as default scheduler name.
|
||||
* Set the name of the Scheduler to create via the SchedulerFactory, as an
|
||||
* alternative to the {@code org.quartz.scheduler.instanceName} property.
|
||||
* <p>If not specified, the name will be taken from Quartz properties
|
||||
* ({@code org.quartz.scheduler.instanceName}), or from the declared
|
||||
* {@code SchedulerFactoryBean} bean name as a fallback.
|
||||
* @see #setBeanName
|
||||
* @see StdSchedulerFactory#PROP_SCHED_INSTANCE_NAME
|
||||
* @see org.quartz.SchedulerFactory#getScheduler()
|
||||
* @see org.quartz.SchedulerFactory#getScheduler(String)
|
||||
*/
|
||||
@@ -467,9 +474,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
|
||||
|
||||
@Override
|
||||
public void setBeanName(String name) {
|
||||
if (this.schedulerName == null) {
|
||||
this.schedulerName = name;
|
||||
}
|
||||
this.beanName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -564,10 +569,22 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
|
||||
|
||||
CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps);
|
||||
if (this.dataSource != null) {
|
||||
mergedProps.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
|
||||
mergedProps.setProperty(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
|
||||
}
|
||||
|
||||
// Determine scheduler name across local settings and Quartz properties...
|
||||
if (this.schedulerName != null) {
|
||||
mergedProps.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName);
|
||||
mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName);
|
||||
}
|
||||
else {
|
||||
String nameProp = mergedProps.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
|
||||
if (nameProp != null) {
|
||||
this.schedulerName = nameProp;
|
||||
}
|
||||
else if (this.beanName != null) {
|
||||
mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.beanName);
|
||||
this.schedulerName = this.beanName;
|
||||
}
|
||||
}
|
||||
|
||||
schedulerFactory.initialize(mergedProps);
|
||||
|
||||
Reference in New Issue
Block a user