Polish "Ensure Flyway/Liquibase runs before Quartz"

See gh-17539
pull/18464/head
Phillip Webb 5 years ago
parent 7e5bd1f281
commit 75a1a24914

@ -22,14 +22,12 @@ import java.util.Properties;
import javax.sql.DataSource; import javax.sql.DataSource;
import liquibase.integration.spring.SpringLiquibase; import liquibase.integration.spring.SpringLiquibase;
import org.flywaydb.core.Flyway;
import org.quartz.Calendar; import org.quartz.Calendar;
import org.quartz.JobDetail; import org.quartz.JobDetail;
import org.quartz.Scheduler; import org.quartz.Scheduler;
import org.quartz.Trigger; import org.quartz.Trigger;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor; import org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@ -163,6 +161,7 @@ public class QuartzAutoConfiguration {
QuartzProperties properties) { QuartzProperties properties) {
DataSource dataSourceToUse = getDataSource(dataSource, quartzDataSource); DataSource dataSourceToUse = getDataSource(dataSource, quartzDataSource);
return new QuartzDataSourceInitializer(dataSourceToUse, resourceLoader, properties); return new QuartzDataSourceInitializer(dataSourceToUse, resourceLoader, properties);
} }
/** /**
@ -171,66 +170,39 @@ public class QuartzAutoConfiguration {
* bean(s). * bean(s).
*/ */
@Configuration @Configuration
protected static class SchedulerQuartzDataSourceInitializerDependencyConfiguration static class QuartzSchedulerDependencyConfiguration {
extends AbstractSchedulerDependsOnBeanFactoryPostProcessor {
SchedulerQuartzDataSourceInitializerDependencyConfiguration() { @Bean
super(QuartzDataSourceInitializer.class); public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerDataSourceInitializerDependsOnBeanFactoryPostProcessor() {
return new SchedulerDependsOnBeanFactoryPostProcessor(QuartzDataSourceInitializer.class);
} }
@Bean
@ConditionalOnBean(FlywayMigrationInitializer.class)
public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerFilywayDependsOnBeanFactoryPostProcessor() {
return new SchedulerDependsOnBeanFactoryPostProcessor(FlywayMigrationInitializer.class);
} }
/** @Bean
* Additional configuration to ensure that {@link SchedulerFactoryBean} and
* {@link Scheduler} beans depend on the {@link SpringLiquibase} bean(s).
*/
@Configuration
@ConditionalOnClass(SpringLiquibase.class)
@ConditionalOnBean(SpringLiquibase.class) @ConditionalOnBean(SpringLiquibase.class)
protected static class SchedulerSpringLiquibaseDependencyConfiguration public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerLiquibaseDependsOnBeanFactoryPostProcessor() {
extends AbstractSchedulerDependsOnBeanFactoryPostProcessor { return new SchedulerDependsOnBeanFactoryPostProcessor(SpringLiquibase.class);
SchedulerSpringLiquibaseDependencyConfiguration() {
super(SpringLiquibase.class);
} }
} }
/**
* Additional configuration to ensure that {@link SchedulerFactoryBean} and
* {@link Scheduler} beans depend on the {@link FlywayMigrationInitializer}
* bean(s).
*/
@Configuration
@ConditionalOnClass(Flyway.class)
@ConditionalOnBean(FlywayMigrationInitializer.class)
protected static class SchedulerFlywayMigrationInitializerDependencyConfiguration
extends AbstractSchedulerDependsOnBeanFactoryPostProcessor {
SchedulerFlywayMigrationInitializerDependencyConfiguration() {
super(FlywayMigrationInitializer.class);
}
} }
/** /**
* {@link BeanFactoryPostProcessor} that can be used to declare that all * {@link AbstractDependsOnBeanFactoryPostProcessor} for Quartz {@link Scheduler} and
* {@link Scheduler} and {@link SchedulerFactoryBean} beans should "depend on" one * {@link SchedulerFactoryBean}.
* or more specific beans.
*/ */
protected abstract static class AbstractSchedulerDependsOnBeanFactoryPostProcessor private static class SchedulerDependsOnBeanFactoryPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
extends AbstractDependsOnBeanFactoryPostProcessor {
/** SchedulerDependsOnBeanFactoryPostProcessor(Class<?>... dependencyTypes) {
* Create an instance with dependency types.
* @param dependencyTypes dependency types
*/
protected AbstractSchedulerDependsOnBeanFactoryPostProcessor(Class<?>... dependencyTypes) {
super(Scheduler.class, SchedulerFactoryBean.class, dependencyTypes); super(Scheduler.class, SchedulerFactoryBean.class, dependencyTypes);
} }
} }
}
} }

Loading…
Cancel
Save