50
50
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
51
51
import org .springframework .context .annotation .Bean ;
52
52
import org .springframework .context .annotation .Configuration ;
53
+ import org .springframework .context .annotation .Import ;
53
54
import org .springframework .core .env .Environment ;
54
55
import org .springframework .jdbc .core .JdbcTemplate ;
55
56
import org .springframework .scheduling .quartz .LocalDataSourceJobStore ;
56
57
import org .springframework .scheduling .quartz .LocalTaskExecutorThreadPool ;
57
58
import org .springframework .scheduling .quartz .QuartzJobBean ;
59
+ import org .springframework .util .Assert ;
58
60
import org .springframework .util .ObjectUtils ;
59
61
60
62
import static org .assertj .core .api .Assertions .assertThat ;
@@ -174,7 +176,7 @@ public void withQuartzProperties() throws Exception {
174
176
175
177
@ Test
176
178
public void withCustomizer () throws Exception {
177
- load (QuartzCustomConfig .class );
179
+ load (QuartzCustomConfiguration .class );
178
180
assertThat (this .context .getBeansOfType (Scheduler .class )).hasSize (1 );
179
181
Scheduler scheduler = this .context .getBean (Scheduler .class );
180
182
assertThat (scheduler .getSchedulerName ()).isEqualTo ("fooScheduler" );
@@ -199,8 +201,14 @@ private void load(Class<?>[] configs, String... environment) {
199
201
this .context = ctx ;
200
202
}
201
203
204
+ @ Import (ComponentThatUsesScheduler .class )
202
205
@ Configuration
203
- protected static class QuartzJobsConfiguration {
206
+ protected static class BaseQuartzConfiguration {
207
+
208
+ }
209
+
210
+ @ Configuration
211
+ protected static class QuartzJobsConfiguration extends BaseQuartzConfiguration {
204
212
205
213
@ Bean
206
214
public JobDetail fooJob () {
@@ -217,7 +225,7 @@ public JobDetail barJob() {
217
225
}
218
226
219
227
@ Configuration
220
- protected static class QuartzFullConfiguration {
228
+ protected static class QuartzFullConfiguration extends BaseQuartzConfiguration {
221
229
222
230
@ Bean
223
231
public JobDetail fooJob () {
@@ -237,7 +245,7 @@ public Trigger fooTrigger() {
237
245
}
238
246
239
247
@ Configuration
240
- protected static class QuartzCalendarsConfiguration {
248
+ protected static class QuartzCalendarsConfiguration extends BaseQuartzConfiguration {
241
249
242
250
@ Bean
243
251
public Calendar weekly () {
@@ -252,7 +260,7 @@ public Calendar monthly() {
252
260
}
253
261
254
262
@ Configuration
255
- protected static class QuartzExecutorConfiguration {
263
+ protected static class QuartzExecutorConfiguration extends BaseQuartzConfiguration {
256
264
257
265
@ Bean
258
266
public Executor executor () {
@@ -262,7 +270,7 @@ public Executor executor() {
262
270
}
263
271
264
272
@ Configuration
265
- protected static class QuartzCustomConfig {
273
+ protected static class QuartzCustomConfiguration extends BaseQuartzConfiguration {
266
274
267
275
@ Bean
268
276
public SchedulerFactoryBeanCustomizer customizer () {
@@ -272,6 +280,17 @@ public SchedulerFactoryBeanCustomizer customizer() {
272
280
273
281
}
274
282
283
+ public static class ComponentThatUsesScheduler {
284
+
285
+ private Scheduler scheduler ;
286
+
287
+ public ComponentThatUsesScheduler (Scheduler scheduler ) {
288
+ Assert .notNull (scheduler , "Scheduler must not be null" );
289
+ this .scheduler = scheduler ;
290
+ }
291
+
292
+ }
293
+
275
294
public static class FooJob extends QuartzJobBean {
276
295
277
296
@ Autowired
0 commit comments