From 73ad17d2cb962883a16ca3629f0e0d4b52c23fa3 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 10 Oct 2018 16:01:59 +0200 Subject: [PATCH] Use standard SpringBeanJobFactory to create Quartz Job instances A recent update to SpringBeanJobFactory provides the same features as our AutowireCapableBeanJobFactory override so this commit removes it in favour of the standard factory. Closes gh-14772 --- .../quartz/AutowireCapableBeanJobFactory.java | 49 ------------------- .../quartz/QuartzAutoConfiguration.java | 6 ++- 2 files changed, 4 insertions(+), 51 deletions(-) delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/AutowireCapableBeanJobFactory.java diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/AutowireCapableBeanJobFactory.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/AutowireCapableBeanJobFactory.java deleted file mode 100644 index e114f17a93..0000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/AutowireCapableBeanJobFactory.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.autoconfigure.quartz; - -import org.quartz.spi.TriggerFiredBundle; - -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.scheduling.quartz.SpringBeanJobFactory; -import org.springframework.util.Assert; - -/** - * Subclass of {@link SpringBeanJobFactory} that supports auto-wiring job beans. - * - * @author Vedran Pavic - * @see Inject application - * context dependencies in Quartz job beans - */ -class AutowireCapableBeanJobFactory extends SpringBeanJobFactory { - - private final AutowireCapableBeanFactory beanFactory; - - AutowireCapableBeanJobFactory(AutowireCapableBeanFactory beanFactory) { - Assert.notNull(beanFactory, "Bean factory must not be null"); - this.beanFactory = beanFactory; - } - - @Override - protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { - Object jobInstance = super.createJobInstance(bundle); - this.beanFactory.autowireBean(jobInstance); - this.beanFactory.initializeBean(jobInstance, null); - return jobInstance; - } - -} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java index de4e317823..57925b40d6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java @@ -42,6 +42,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; import org.springframework.core.io.ResourceLoader; import org.springframework.scheduling.quartz.SchedulerFactoryBean; +import org.springframework.scheduling.quartz.SpringBeanJobFactory; import org.springframework.transaction.PlatformTransactionManager; /** @@ -88,8 +89,9 @@ public class QuartzAutoConfiguration { @ConditionalOnMissingBean public SchedulerFactoryBean quartzScheduler() { SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); - schedulerFactoryBean.setJobFactory(new AutowireCapableBeanJobFactory( - this.applicationContext.getAutowireCapableBeanFactory())); + SpringBeanJobFactory jobFactory = new SpringBeanJobFactory(); + jobFactory.setApplicationContext(this.applicationContext); + schedulerFactoryBean.setJobFactory(jobFactory); if (this.properties.getSchedulerName() != null) { schedulerFactoryBean.setSchedulerName(this.properties.getSchedulerName()); }