|
|
@ -21,6 +21,7 @@ import java.util.Properties;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import liquibase.integration.spring.SpringLiquibase;
|
|
|
|
import org.quartz.Calendar;
|
|
|
|
import org.quartz.Calendar;
|
|
|
|
import org.quartz.JobDetail;
|
|
|
|
import org.quartz.JobDetail;
|
|
|
|
import org.quartz.Scheduler;
|
|
|
|
import org.quartz.Scheduler;
|
|
|
@ -30,11 +31,15 @@ import org.springframework.beans.factory.ObjectProvider;
|
|
|
|
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;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer;
|
|
|
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
@ -56,7 +61,8 @@ import org.springframework.transaction.PlatformTransactionManager;
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@ConditionalOnClass({ Scheduler.class, SchedulerFactoryBean.class, PlatformTransactionManager.class })
|
|
|
|
@ConditionalOnClass({ Scheduler.class, SchedulerFactoryBean.class, PlatformTransactionManager.class })
|
|
|
|
@EnableConfigurationProperties(QuartzProperties.class)
|
|
|
|
@EnableConfigurationProperties(QuartzProperties.class)
|
|
|
|
@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
|
|
|
|
@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
|
|
|
|
|
|
|
|
LiquibaseAutoConfiguration.class, FlywayAutoConfiguration.class })
|
|
|
|
public class QuartzAutoConfiguration {
|
|
|
|
public class QuartzAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
@ -123,22 +129,48 @@ 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
public static DataSourceInitializerSchedulerDependencyPostProcessor dataSourceInitializerSchedulerDependencyPostProcessor() {
|
|
|
|
|
|
|
|
return new DataSourceInitializerSchedulerDependencyPostProcessor();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static class DataSourceInitializerSchedulerDependencyPostProcessor
|
|
|
|
/**
|
|
|
|
extends AbstractDependsOnBeanFactoryPostProcessor {
|
|
|
|
* Additional configuration to ensure that {@link SchedulerFactoryBean} and
|
|
|
|
|
|
|
|
* {@link Scheduler} beans depend on the {@link QuartzDataSourceInitializer}
|
|
|
|
|
|
|
|
* bean(s).
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
|
|
|
|
static class QuartzSchedulerDependencyConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerDataSourceInitializerDependsOnBeanFactoryPostProcessor() {
|
|
|
|
|
|
|
|
return new SchedulerDependsOnBeanFactoryPostProcessor(QuartzDataSourceInitializer.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
@ConditionalOnBean(FlywayMigrationInitializer.class)
|
|
|
|
|
|
|
|
public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerFilywayDependsOnBeanFactoryPostProcessor() {
|
|
|
|
|
|
|
|
return new SchedulerDependsOnBeanFactoryPostProcessor(FlywayMigrationInitializer.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DataSourceInitializerSchedulerDependencyPostProcessor() {
|
|
|
|
@Bean
|
|
|
|
super(Scheduler.class, SchedulerFactoryBean.class, "quartzDataSourceInitializer");
|
|
|
|
@ConditionalOnBean(SpringLiquibase.class)
|
|
|
|
|
|
|
|
public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerLiquibaseDependsOnBeanFactoryPostProcessor() {
|
|
|
|
|
|
|
|
return new SchedulerDependsOnBeanFactoryPostProcessor(SpringLiquibase.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* {@link AbstractDependsOnBeanFactoryPostProcessor} for Quartz {@link Scheduler} and
|
|
|
|
|
|
|
|
* {@link SchedulerFactoryBean}.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static class SchedulerDependsOnBeanFactoryPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SchedulerDependsOnBeanFactoryPostProcessor(Class<?>... dependencyTypes) {
|
|
|
|
|
|
|
|
super(Scheduler.class, SchedulerFactoryBean.class, dependencyTypes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|