|
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
|
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 | private final QuartzProperties properties;
|
@@ -155,22 +161,48 @@ public QuartzDataSourceInitializer quartzDataSourceInitializer(DataSource dataSo
|
155 | 161 | QuartzProperties properties) {
|
156 | 162 | DataSource dataSourceToUse = getDataSource(dataSource, quartzDataSource);
|
157 | 163 | return new QuartzDataSourceInitializer(dataSourceToUse, resourceLoader, properties);
|
158 |
| - } |
159 | 164 |
|
160 |
| - @Bean |
161 |
| - public static DataSourceInitializerSchedulerDependencyPostProcessor dataSourceInitializerSchedulerDependencyPostProcessor() { |
162 |
| - return new DataSourceInitializerSchedulerDependencyPostProcessor(); |
163 | 165 | }
|
164 | 166 |
|
165 |
| - private static class DataSourceInitializerSchedulerDependencyPostProcessor |
166 |
| - extends AbstractDependsOnBeanFactoryPostProcessor { |
| 167 | + /** |
| 168 | + * Additional configuration to ensure that {@link SchedulerFactoryBean} and |
| 169 | + * {@link Scheduler} beans depend on the {@link QuartzDataSourceInitializer} |
| 170 | + * bean(s). |
| 171 | + */ |
| 172 | + @Configuration |
| 173 | + static class QuartzSchedulerDependencyConfiguration { |
| 174 | + |
| 175 | + @Bean |
| 176 | + public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerDataSourceInitializerDependsOnBeanFactoryPostProcessor() { |
| 177 | + return new SchedulerDependsOnBeanFactoryPostProcessor(QuartzDataSourceInitializer.class); |
| 178 | + } |
| 179 | + |
| 180 | + @Bean |
| 181 | + @ConditionalOnBean(FlywayMigrationInitializer.class) |
| 182 | + public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerFilywayDependsOnBeanFactoryPostProcessor() { |
| 183 | + return new SchedulerDependsOnBeanFactoryPostProcessor(FlywayMigrationInitializer.class); |
| 184 | + } |
167 | 185 |
|
168 |
| - DataSourceInitializerSchedulerDependencyPostProcessor() { |
169 |
| - super(Scheduler.class, SchedulerFactoryBean.class, "quartzDataSourceInitializer"); |
| 186 | + @Bean |
| 187 | + @ConditionalOnBean(SpringLiquibase.class) |
| 188 | + public static SchedulerDependsOnBeanFactoryPostProcessor quartzSchedulerLiquibaseDependsOnBeanFactoryPostProcessor() { |
| 189 | + return new SchedulerDependsOnBeanFactoryPostProcessor(SpringLiquibase.class); |
170 | 190 | }
|
171 | 191 |
|
172 | 192 | }
|
173 | 193 |
|
174 | 194 | }
|
175 | 195 |
|
| 196 | + /** |
| 197 | + * {@link AbstractDependsOnBeanFactoryPostProcessor} for Quartz {@link Scheduler} and |
| 198 | + * {@link SchedulerFactoryBean}. |
| 199 | + */ |
| 200 | + private static class SchedulerDependsOnBeanFactoryPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor { |
| 201 | + |
| 202 | + SchedulerDependsOnBeanFactoryPostProcessor(Class<?>... dependencyTypes) { |
| 203 | + super(Scheduler.class, SchedulerFactoryBean.class, dependencyTypes); |
| 204 | + } |
| 205 | + |
| 206 | + } |
| 207 | + |
176 | 208 | }
|
0 commit comments