|
21 | 21 |
|
22 | 22 | import javax.sql.DataSource;
|
23 | 23 |
|
| 24 | +import liquibase.integration.spring.SpringLiquibase; |
| 25 | +import org.flywaydb.core.Flyway; |
24 | 26 | import org.quartz.Calendar;
|
25 | 27 | import org.quartz.JobDetail;
|
26 | 28 | import org.quartz.Scheduler;
|
27 | 29 | import org.quartz.Trigger;
|
28 | 30 |
|
29 | 31 | import org.springframework.beans.factory.ObjectProvider;
|
| 32 | +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; |
30 | 33 | import org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor;
|
31 | 34 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
32 | 35 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
| 36 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
33 | 37 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
34 | 38 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
35 | 39 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
36 | 40 | import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
| 41 | +import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; |
| 42 | +import org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer; |
37 | 43 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
| 44 | +import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; |
38 | 45 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
39 | 46 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
40 | 47 | import org.springframework.context.ApplicationContext;
|
|
56 | 63 | @Configuration
|
57 | 64 | @ConditionalOnClass({ Scheduler.class, SchedulerFactoryBean.class, PlatformTransactionManager.class })
|
58 | 65 | @EnableConfigurationProperties(QuartzProperties.class)
|
59 |
| -@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) |
| 66 | +@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, |
| 67 | + LiquibaseAutoConfiguration.class, FlywayAutoConfiguration.class }) |
60 | 68 | public class QuartzAutoConfiguration {
|
61 | 69 |
|
62 | 70 | private final QuartzProperties properties;
|
@@ -157,16 +165,68 @@ public QuartzDataSourceInitializer quartzDataSourceInitializer(DataSource dataSo
|
157 | 165 | return new QuartzDataSourceInitializer(dataSourceToUse, resourceLoader, properties);
|
158 | 166 | }
|
159 | 167 |
|
160 |
| - @Bean |
161 |
| - public static DataSourceInitializerSchedulerDependencyPostProcessor dataSourceInitializerSchedulerDependencyPostProcessor() { |
162 |
| - return new DataSourceInitializerSchedulerDependencyPostProcessor(); |
| 168 | + /** |
| 169 | + * Additional configuration to ensure that {@link SchedulerFactoryBean} and |
| 170 | + * {@link Scheduler} beans depend on the {@link QuartzDataSourceInitializer} |
| 171 | + * bean(s). |
| 172 | + */ |
| 173 | + @Configuration |
| 174 | + protected static class SchedulerQuartzDataSourceInitializerDependencyConfiguration |
| 175 | + extends AbstractSchedulerDependsOnBeanFactoryPostProcessor { |
| 176 | + |
| 177 | + SchedulerQuartzDataSourceInitializerDependencyConfiguration() { |
| 178 | + super(QuartzDataSourceInitializer.class); |
| 179 | + } |
| 180 | + |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * Additional configuration to ensure that {@link SchedulerFactoryBean} and |
| 185 | + * {@link Scheduler} beans depend on the {@link SpringLiquibase} bean(s). |
| 186 | + */ |
| 187 | + @Configuration |
| 188 | + @ConditionalOnClass(SpringLiquibase.class) |
| 189 | + @ConditionalOnBean(SpringLiquibase.class) |
| 190 | + protected static class SchedulerSpringLiquibaseDependencyConfiguration |
| 191 | + extends AbstractSchedulerDependsOnBeanFactoryPostProcessor { |
| 192 | + |
| 193 | + SchedulerSpringLiquibaseDependencyConfiguration() { |
| 194 | + super(SpringLiquibase.class); |
| 195 | + } |
| 196 | + |
| 197 | + } |
| 198 | + |
| 199 | + /** |
| 200 | + * Additional configuration to ensure that {@link SchedulerFactoryBean} and |
| 201 | + * {@link Scheduler} beans depend on the {@link FlywayMigrationInitializer} |
| 202 | + * bean(s). |
| 203 | + */ |
| 204 | + @Configuration |
| 205 | + @ConditionalOnClass(Flyway.class) |
| 206 | + @ConditionalOnBean(FlywayMigrationInitializer.class) |
| 207 | + protected static class SchedulerFlywayMigrationInitializerDependencyConfiguration |
| 208 | + extends AbstractSchedulerDependsOnBeanFactoryPostProcessor { |
| 209 | + |
| 210 | + SchedulerFlywayMigrationInitializerDependencyConfiguration() { |
| 211 | + super(FlywayMigrationInitializer.class); |
| 212 | + } |
| 213 | + |
163 | 214 | }
|
164 | 215 |
|
165 |
| - private static class DataSourceInitializerSchedulerDependencyPostProcessor |
| 216 | + /** |
| 217 | + * {@link BeanFactoryPostProcessor} that can be used to declare that all |
| 218 | + * {@link Scheduler} and {@link SchedulerFactoryBean} beans should "depend on" one |
| 219 | + * or more specific beans. |
| 220 | + */ |
| 221 | + protected abstract static class AbstractSchedulerDependsOnBeanFactoryPostProcessor |
166 | 222 | extends AbstractDependsOnBeanFactoryPostProcessor {
|
167 | 223 |
|
168 |
| - DataSourceInitializerSchedulerDependencyPostProcessor() { |
169 |
| - super(Scheduler.class, SchedulerFactoryBean.class, "quartzDataSourceInitializer"); |
| 224 | + /** |
| 225 | + * Create an instance with dependency types. |
| 226 | + * @param dependencyTypes dependency types |
| 227 | + */ |
| 228 | + protected AbstractSchedulerDependsOnBeanFactoryPostProcessor(Class<?>... dependencyTypes) { |
| 229 | + super(Scheduler.class, SchedulerFactoryBean.class, dependencyTypes); |
170 | 230 | }
|
171 | 231 |
|
172 | 232 | }
|
|
0 commit comments