|
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;
|
33 | 36 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
34 | 37 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
35 | 38 | import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
| 39 | +import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; |
| 40 | +import org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer; |
36 | 41 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
| 42 | +import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; |
37 | 43 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
38 | 44 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
39 | 45 | import org.springframework.context.ApplicationContext;
|
|
55 | 61 | @Configuration(proxyBeanMethods = false)
|
56 | 62 | @ConditionalOnClass({ Scheduler.class, SchedulerFactoryBean.class, PlatformTransactionManager.class })
|
57 | 63 | @EnableConfigurationProperties(QuartzProperties.class)
|
58 |
| -@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) |
| 64 | +@AutoConfigureAfter({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, |
| 65 | + LiquibaseAutoConfiguration.class, FlywayAutoConfiguration.class }) |
59 | 66 | public class QuartzAutoConfiguration {
|
60 | 67 |
|
61 | 68 | @Bean
|
@@ -125,16 +132,66 @@ public QuartzDataSourceInitializer quartzDataSourceInitializer(DataSource dataSo
|
125 | 132 | return new QuartzDataSourceInitializer(dataSourceToUse, resourceLoader, properties);
|
126 | 133 | }
|
127 | 134 |
|
128 |
| - @Bean |
129 |
| - public static DataSourceInitializerSchedulerDependencyPostProcessor dataSourceInitializerSchedulerDependencyPostProcessor() { |
130 |
| - return new DataSourceInitializerSchedulerDependencyPostProcessor(); |
| 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 | + protected static class SchedulerQuartzDataSourceInitializerDependencyConfiguration |
| 142 | + extends AbstractSchedulerDependsOnBeanFactoryPostProcessor { |
| 143 | + |
| 144 | + SchedulerQuartzDataSourceInitializerDependencyConfiguration() { |
| 145 | + super(QuartzDataSourceInitializer.class); |
| 146 | + } |
| 147 | + |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * Additional configuration to ensure that {@link SchedulerFactoryBean} and |
| 152 | + * {@link Scheduler} beans depend on the {@link SpringLiquibase} bean(s). |
| 153 | + */ |
| 154 | + @Configuration(proxyBeanMethods = false) |
| 155 | + @ConditionalOnClass(SpringLiquibase.class) |
| 156 | + protected static class SchedulerSpringLiquibaseDependencyConfiguration |
| 157 | + extends AbstractSchedulerDependsOnBeanFactoryPostProcessor { |
| 158 | + |
| 159 | + SchedulerSpringLiquibaseDependencyConfiguration() { |
| 160 | + super(SpringLiquibase.class); |
| 161 | + } |
| 162 | + |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Additional configuration to ensure that {@link SchedulerFactoryBean} and |
| 167 | + * {@link Scheduler} beans depend on the {@link FlywayMigrationInitializer} |
| 168 | + * bean(s). |
| 169 | + */ |
| 170 | + @Configuration(proxyBeanMethods = false) |
| 171 | + @ConditionalOnClass(Flyway.class) |
| 172 | + protected static class SchedulerFlywayMigrationInitializerDependencyConfiguration |
| 173 | + extends AbstractSchedulerDependsOnBeanFactoryPostProcessor { |
| 174 | + |
| 175 | + SchedulerFlywayMigrationInitializerDependencyConfiguration() { |
| 176 | + super(FlywayMigrationInitializer.class); |
| 177 | + } |
| 178 | + |
131 | 179 | }
|
132 | 180 |
|
133 |
| - private static class DataSourceInitializerSchedulerDependencyPostProcessor |
| 181 | + /** |
| 182 | + * {@link BeanFactoryPostProcessor} that can be used to declare that all |
| 183 | + * {@link Scheduler} and {@link SchedulerFactoryBean} beans should "depend on" one |
| 184 | + * or more specific beans. |
| 185 | + */ |
| 186 | + protected abstract static class AbstractSchedulerDependsOnBeanFactoryPostProcessor |
134 | 187 | extends AbstractDependsOnBeanFactoryPostProcessor {
|
135 | 188 |
|
136 |
| - DataSourceInitializerSchedulerDependencyPostProcessor() { |
137 |
| - super(Scheduler.class, SchedulerFactoryBean.class, "quartzDataSourceInitializer"); |
| 189 | + /** |
| 190 | + * Create an instance with dependency types. |
| 191 | + * @param dependencyTypes dependency types |
| 192 | + */ |
| 193 | + protected AbstractSchedulerDependsOnBeanFactoryPostProcessor(Class<?>... dependencyTypes) { |
| 194 | + super(Scheduler.class, SchedulerFactoryBean.class, dependencyTypes); |
138 | 195 | }
|
139 | 196 |
|
140 | 197 | }
|
|
0 commit comments