|
21 | 21 |
|
22 | 22 | import javax.sql.DataSource;
|
23 | 23 |
|
| 24 | +import liquibase.integration.spring.SpringLiquibase; |
24 | 25 | import org.quartz.Calendar;
|
25 | 26 | import org.quartz.JobDetail;
|
26 | 27 | import org.quartz.Scheduler;
|
|
30 | 31 | import org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor;
|
31 | 32 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
32 | 33 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
| 34 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
33 | 35 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
34 | 36 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
35 | 37 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
36 | 38 | import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
| 39 | +import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; |
| 40 | +import org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer; |
37 | 41 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
| 42 | +import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; |
38 | 43 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
39 | 44 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
40 | 45 | import org.springframework.context.ApplicationContext;
|
|
56 | 61 | @Configuration(proxyBeanMethods = false)
|
57 | 62 | @ConditionalOnClass({ Scheduler.class, SchedulerFactoryBean.class, PlatformTransactionManager.class })
|
58 | 63 | @EnableConfigurationProperties(QuartzProperties.class)
|
59 |
| -@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) |
| 64 | +@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, |
| 65 | + LiquibaseAutoConfiguration.class, FlywayAutoConfiguration.class }) |
60 | 66 | public class QuartzAutoConfiguration {
|
61 | 67 |
|
62 | 68 | @Bean
|
@@ -123,22 +129,48 @@ public QuartzDataSourceInitializer quartzDataSourceInitializer(DataSource dataSo
|
123 | 129 | QuartzProperties properties) {
|
124 | 130 | DataSource dataSourceToUse = getDataSource(dataSource, quartzDataSource);
|
125 | 131 | return new QuartzDataSourceInitializer(dataSourceToUse, resourceLoader, properties);
|
126 |
| - } |
127 | 132 |
|
128 |
| - @Bean |
129 |
| - public static DataSourceInitializerSchedulerDependencyPostProcessor dataSourceInitializerSchedulerDependencyPostProcessor() { |
130 |
| - return new DataSourceInitializerSchedulerDependencyPostProcessor(); |
131 | 133 | }
|
132 | 134 |
|
133 |
| - private static class DataSourceInitializerSchedulerDependencyPostProcessor |
134 |
| - extends AbstractDependsOnBeanFactoryPostProcessor { |
| 135 | + /** |
| 136 | + * Additional configuration to ensure that {@link SchedulerFactoryBean} and |
| 137 | + * {@link Scheduler} beans depend on the {@link QuartzDataSourceInitializer} |
| 138 | + * bean(s). |
| 139 | + */ |
| 140 | + @Configuration(proxyBeanMethods = false) |
| 141 | + static class QuartzSchedulerDependencyConfiguration { |
| 142 | + |
| 143 | + @Bean |
| 144 | + public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerDataSourceInitializerDependsOnBeanFactoryPostProcessor() { |
| 145 | + return new SchedulerDependsOnBeanFactoryPostProcessor(QuartzDataSourceInitializer.class); |
| 146 | + } |
| 147 | + |
| 148 | + @Bean |
| 149 | + @ConditionalOnBean(FlywayMigrationInitializer.class) |
| 150 | + public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerFilywayDependsOnBeanFactoryPostProcessor() { |
| 151 | + return new SchedulerDependsOnBeanFactoryPostProcessor(FlywayMigrationInitializer.class); |
| 152 | + } |
135 | 153 |
|
136 |
| - DataSourceInitializerSchedulerDependencyPostProcessor() { |
137 |
| - super(Scheduler.class, SchedulerFactoryBean.class, "quartzDataSourceInitializer"); |
| 154 | + @Bean |
| 155 | + @ConditionalOnBean(SpringLiquibase.class) |
| 156 | + public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerLiquibaseDependsOnBeanFactoryPostProcessor() { |
| 157 | + return new SchedulerDependsOnBeanFactoryPostProcessor(SpringLiquibase.class); |
138 | 158 | }
|
139 | 159 |
|
140 | 160 | }
|
141 | 161 |
|
142 | 162 | }
|
143 | 163 |
|
| 164 | + /** |
| 165 | + * {@link AbstractDependsOnBeanFactoryPostProcessor} for Quartz {@link Scheduler} and |
| 166 | + * {@link SchedulerFactoryBean}. |
| 167 | + */ |
| 168 | + private static class SchedulerDependsOnBeanFactoryPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor { |
| 169 | + |
| 170 | + SchedulerDependsOnBeanFactoryPostProcessor(Class<?>... dependencyTypes) { |
| 171 | + super(Scheduler.class, SchedulerFactoryBean.class, dependencyTypes); |
| 172 | + } |
| 173 | + |
| 174 | + } |
| 175 | + |
144 | 176 | }
|
0 commit comments