@@ -216,10 +216,10 @@ public static DataSource getConfigTimeNonTransactionalDataSource() {
216
216
217
217
/**
218
218
* Set the Quartz {@link SchedulerFactory} implementation to use.
219
- * <p>Default is {@link StdSchedulerFactory}, reading in the standard
220
- * {@code quartz.properties} from {@code quartz.jar}.
221
- * To use custom Quartz properties, specify the "configLocation"
222
- * or "quartzProperties" bean property on this FactoryBean .
219
+ * <p>Default is the {@link StdSchedulerFactory} class , reading in the standard
220
+ * {@code quartz.properties} from {@code quartz.jar}. For applying custom Quartz
221
+ * properties, specify {@link #setConfigLocation "configLocation"} or
222
+ * {@link #setQuartzProperties "quartzProperties"} on {@code SchedulerFactoryBean} .
223
223
* @see org.quartz.impl.StdSchedulerFactory
224
224
* @see #setConfigLocation
225
225
* @see #setQuartzProperties
@@ -230,10 +230,15 @@ public void setSchedulerFactoryClass(Class<? extends SchedulerFactory> scheduler
230
230
231
231
/**
232
232
* Set an external Quartz {@link SchedulerFactory} instance to use.
233
- * <p>Default is an internal {@link StdSchedulerFactory} instance.
234
- * If this method is being called, it overrides any class specified
235
- * through {@link #setSchedulerFactoryClass}.
236
- * @since 5.0.4
233
+ * <p>Default is an internal {@link StdSchedulerFactory} instance. If this method is
234
+ * called, it overrides any class specified through {@link #setSchedulerFactoryClass}.
235
+ * <p>An externally provided {@code SchedulerFactory} instance may get initialized
236
+ * from local {@code SchedulerFactoryBean} settings (such as {@link #setConfigLocation}
237
+ * or {@link #setQuartzProperties}) but only if it extends from {@link StdSchedulerFactory},
238
+ * inheriting the common {@link StdSchedulerFactory#initialize(Properties)} method.
239
+ * Otherwise, all such local settings will be ignored here in {@code SchedulerFactoryBean},
240
+ * expecting the external {@code SchedulerFactory} instance to get initialized on its own.
241
+ * @since 4.3.15
237
242
* @see #setSchedulerFactoryClass
238
243
*/
239
244
public void setSchedulerFactory (SchedulerFactory schedulerFactory ) {
@@ -480,9 +485,7 @@ public void afterPropertiesSet() throws Exception {
480
485
}
481
486
482
487
// Initialize the SchedulerFactory instance...
483
- SchedulerFactory schedulerFactory = (this .schedulerFactory != null ? this .schedulerFactory :
484
- BeanUtils .instantiateClass (this .schedulerFactoryClass ));
485
- initSchedulerFactory (schedulerFactory );
488
+ SchedulerFactory schedulerFactory = prepareSchedulerFactory ();
486
489
487
490
if (this .resourceLoader != null ) {
488
491
// Make given ResourceLoader available for SchedulerFactory configuration.
@@ -540,22 +543,39 @@ public void afterPropertiesSet() throws Exception {
540
543
541
544
542
545
/**
543
- * Load and/or apply Quartz properties to the given SchedulerFactory .
544
- * @param schedulerFactory the SchedulerFactory to initialize
546
+ * Create a SchedulerFactory if necessary and apply locally defined Quartz properties to it .
547
+ * @return the initialized SchedulerFactory
545
548
*/
546
- private void initSchedulerFactory (SchedulerFactory schedulerFactory ) throws SchedulerException , IOException {
547
- if (!(schedulerFactory instanceof StdSchedulerFactory )) {
548
- if (this .configLocation != null || this .quartzProperties != null ||
549
+ private SchedulerFactory prepareSchedulerFactory () throws SchedulerException , IOException {
550
+ SchedulerFactory schedulerFactory = this .schedulerFactory ;
551
+ if (schedulerFactory != null ) {
552
+ if (schedulerFactory instanceof StdSchedulerFactory ) {
553
+ initSchedulerFactory ((StdSchedulerFactory ) schedulerFactory );
554
+ }
555
+ // Otherwise, assume that externally provided factory has been initialized with appropriate settings...
556
+ }
557
+ else {
558
+ // Create local SchedulerFactory instance (typically a StdSchedulerFactory)
559
+ schedulerFactory = BeanUtils .instantiateClass (this .schedulerFactoryClass );
560
+ if (schedulerFactory instanceof StdSchedulerFactory ) {
561
+ initSchedulerFactory ((StdSchedulerFactory ) schedulerFactory );
562
+ }
563
+ else if (this .configLocation != null || this .quartzProperties != null ||
549
564
this .taskExecutor != null || this .dataSource != null ) {
550
565
throw new IllegalArgumentException (
551
566
"StdSchedulerFactory required for applying Quartz properties: " + schedulerFactory );
552
567
}
553
- // Otherwise assume that no initialization is necessary...
554
- return ;
568
+ // Otherwise, no local settings to be applied via StdSchedulerFactory.initialize(Properties)
555
569
}
570
+ return schedulerFactory ;
571
+ }
556
572
573
+ /**
574
+ * Initialize the given SchedulerFactory, applying locally defined Quartz properties to it.
575
+ * @param schedulerFactory the SchedulerFactory to initialize
576
+ */
577
+ private void initSchedulerFactory (StdSchedulerFactory schedulerFactory ) throws SchedulerException , IOException {
557
578
Properties mergedProps = new Properties ();
558
-
559
579
if (this .resourceLoader != null ) {
560
580
mergedProps .setProperty (StdSchedulerFactory .PROP_SCHED_CLASS_LOAD_HELPER_CLASS ,
561
581
ResourceLoaderClassLoadHelper .class .getName ());
@@ -580,17 +600,14 @@ private void initSchedulerFactory(SchedulerFactory schedulerFactory) throws Sche
580
600
}
581
601
582
602
CollectionUtils .mergePropertiesIntoMap (this .quartzProperties , mergedProps );
583
-
584
603
if (this .dataSource != null ) {
585
604
mergedProps .put (StdSchedulerFactory .PROP_JOB_STORE_CLASS , LocalDataSourceJobStore .class .getName ());
586
605
}
587
-
588
- // Make sure to set the scheduler name as configured in the Spring configuration.
589
606
if (this .schedulerName != null ) {
590
607
mergedProps .put (StdSchedulerFactory .PROP_SCHED_INSTANCE_NAME , this .schedulerName );
591
608
}
592
609
593
- (( StdSchedulerFactory ) schedulerFactory ) .initialize (mergedProps );
610
+ schedulerFactory .initialize (mergedProps );
594
611
}
595
612
596
613
/**
0 commit comments