@@ -192,9 +192,6 @@ public static DataSource getConfigTimeNonTransactionalDataSource() {
192
192
@ Nullable
193
193
private Map <String , ?> schedulerContextMap ;
194
194
195
- @ Nullable
196
- private ApplicationContext applicationContext ;
197
-
198
195
@ Nullable
199
196
private String applicationContextSchedulerContextKey ;
200
197
@@ -213,6 +210,12 @@ public static DataSource getConfigTimeNonTransactionalDataSource() {
213
210
214
211
private boolean waitForJobsToCompleteOnShutdown = false ;
215
212
213
+ @ Nullable
214
+ private String beanName ;
215
+
216
+ @ Nullable
217
+ private ApplicationContext applicationContext ;
218
+
216
219
@ Nullable
217
220
private Scheduler scheduler ;
218
221
@@ -252,9 +255,13 @@ public void setSchedulerFactoryClass(Class<? extends SchedulerFactory> scheduler
252
255
}
253
256
254
257
/**
255
- * Set the name of the Scheduler to create via the SchedulerFactory.
256
- * <p>If not specified, the bean name will be used as default scheduler name.
258
+ * Set the name of the Scheduler to create via the SchedulerFactory, as an
259
+ * alternative to the {@code org.quartz.scheduler.instanceName} property.
260
+ * <p>If not specified, the name will be taken from Quartz properties
261
+ * ({@code org.quartz.scheduler.instanceName}), or from the declared
262
+ * {@code SchedulerFactoryBean} bean name as a fallback.
257
263
* @see #setBeanName
264
+ * @see StdSchedulerFactory#PROP_SCHED_INSTANCE_NAME
258
265
* @see org.quartz.SchedulerFactory#getScheduler()
259
266
* @see org.quartz.SchedulerFactory#getScheduler(String)
260
267
*/
@@ -467,9 +474,7 @@ public void setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnSh
467
474
468
475
@ Override
469
476
public void setBeanName (String name ) {
470
- if (this .schedulerName == null ) {
471
- this .schedulerName = name ;
472
- }
477
+ this .beanName = name ;
473
478
}
474
479
475
480
@ Override
@@ -564,10 +569,22 @@ private void initSchedulerFactory(StdSchedulerFactory schedulerFactory) throws S
564
569
565
570
CollectionUtils .mergePropertiesIntoMap (this .quartzProperties , mergedProps );
566
571
if (this .dataSource != null ) {
567
- mergedProps .put (StdSchedulerFactory .PROP_JOB_STORE_CLASS , LocalDataSourceJobStore .class .getName ());
572
+ mergedProps .setProperty (StdSchedulerFactory .PROP_JOB_STORE_CLASS , LocalDataSourceJobStore .class .getName ());
568
573
}
574
+
575
+ // Determine scheduler name across local settings and Quartz properties...
569
576
if (this .schedulerName != null ) {
570
- mergedProps .put (StdSchedulerFactory .PROP_SCHED_INSTANCE_NAME , this .schedulerName );
577
+ mergedProps .setProperty (StdSchedulerFactory .PROP_SCHED_INSTANCE_NAME , this .schedulerName );
578
+ }
579
+ else {
580
+ String nameProp = mergedProps .getProperty (StdSchedulerFactory .PROP_SCHED_INSTANCE_NAME );
581
+ if (nameProp != null ) {
582
+ this .schedulerName = nameProp ;
583
+ }
584
+ else if (this .beanName != null ) {
585
+ mergedProps .setProperty (StdSchedulerFactory .PROP_SCHED_INSTANCE_NAME , this .beanName );
586
+ this .schedulerName = this .beanName ;
587
+ }
571
588
}
572
589
573
590
schedulerFactory .initialize (mergedProps );
0 commit comments