@@ -46,20 +46,24 @@ public class SchedulerAccessorBean extends SchedulerAccessor implements BeanFact
46
46
47
47
48
48
/**
49
- * Specify the Quartz Scheduler to operate on via its scheduler name in the Spring
49
+ * Specify the Quartz {@link Scheduler} to operate on via its scheduler name in the Spring
50
50
* application context or also in the Quartz {@link org.quartz.impl.SchedulerRepository}.
51
51
* <p>Schedulers can be registered in the repository through custom bootstrapping,
52
52
* e.g. via the {@link org.quartz.impl.StdSchedulerFactory} or
53
53
* {@link org.quartz.impl.DirectSchedulerFactory} factory classes.
54
54
* However, in general, it's preferable to use Spring's {@link SchedulerFactoryBean}
55
55
* which includes the job/trigger/listener capabilities of this accessor as well.
56
+ * <p>If not specified, this accessor will try to retrieve a default {@link Scheduler}
57
+ * bean from the containing application context.
56
58
*/
57
59
public void setSchedulerName (String schedulerName ) {
58
60
this .schedulerName = schedulerName ;
59
61
}
60
62
61
63
/**
62
- * Specify the Quartz Scheduler instance to operate on.
64
+ * Specify the Quartz {@link Scheduler} instance to operate on.
65
+ * <p>If not specified, this accessor will try to retrieve a default {@link Scheduler}
66
+ * bean from the containing application context.
63
67
*/
64
68
public void setScheduler (Scheduler scheduler ) {
65
69
this .scheduler = scheduler ;
@@ -82,12 +86,7 @@ public void setBeanFactory(BeanFactory beanFactory) {
82
86
@ Override
83
87
public void afterPropertiesSet () throws SchedulerException {
84
88
if (this .scheduler == null ) {
85
- if (this .schedulerName != null ) {
86
- this .scheduler = findScheduler (this .schedulerName );
87
- }
88
- else {
89
- throw new IllegalStateException ("No Scheduler specified" );
90
- }
89
+ this .scheduler = (this .schedulerName != null ? findScheduler (this .schedulerName ) : findDefaultScheduler ());
91
90
}
92
91
registerListeners ();
93
92
registerJobsAndTriggers ();
@@ -111,4 +110,14 @@ protected Scheduler findScheduler(String schedulerName) throws SchedulerExceptio
111
110
return schedulerInRepo ;
112
111
}
113
112
113
+ protected Scheduler findDefaultScheduler () {
114
+ if (this .beanFactory != null ) {
115
+ return this .beanFactory .getBean (Scheduler .class );
116
+ }
117
+ else {
118
+ throw new IllegalStateException (
119
+ "No Scheduler specified, and cannot find a default Scheduler without a BeanFactory" );
120
+ }
121
+ }
122
+
114
123
}
0 commit comments