|
17 | 17 |
|
18 | 18 | import javax.sql.DataSource; |
19 | 19 |
|
| 20 | +import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; |
20 | 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
21 | 22 | import org.springframework.boot.jdbc.DatabaseDriver; |
22 | 23 | import org.springframework.context.annotation.Bean; |
| 24 | +import org.springframework.context.annotation.Conditional; |
23 | 25 | import org.springframework.context.annotation.Configuration; |
24 | 26 | import org.springframework.core.io.ResourceLoader; |
25 | 27 | import org.springframework.jdbc.core.JdbcTemplate; |
@@ -47,10 +49,28 @@ JdbcEventPublicationRepository jdbcEventPublicationRepository(JdbcTemplate jdbcT |
47 | 49 | } |
48 | 50 |
|
49 | 51 | @Bean |
50 | | - @ConditionalOnProperty(name = "spring.modulith.events.jdbc-schema-initialization.enabled", havingValue = "true") |
| 52 | + @Conditional(SchemaInitializationEnabled.class) |
51 | 53 | DatabaseSchemaInitializer databaseSchemaInitializer(JdbcTemplate jdbcTemplate, ResourceLoader resourceLoader, |
52 | 54 | DatabaseType databaseType) { |
53 | 55 |
|
54 | 56 | return new DatabaseSchemaInitializer(jdbcTemplate, resourceLoader, databaseType); |
55 | 57 | } |
| 58 | + |
| 59 | + /** |
| 60 | + * Combined condition to support the legacy schema initialization property as well as the new one. |
| 61 | + * |
| 62 | + * @author Oliver Drotbohm |
| 63 | + */ |
| 64 | + static class SchemaInitializationEnabled extends AnyNestedCondition { |
| 65 | + |
| 66 | + public SchemaInitializationEnabled() { |
| 67 | + super(ConfigurationPhase.PARSE_CONFIGURATION); |
| 68 | + } |
| 69 | + |
| 70 | + @ConditionalOnProperty(name = "spring.modulith.events.jdbc-schema-initialization.enabled", havingValue = "true") |
| 71 | + static class LegacyPropertyEnabled {} |
| 72 | + |
| 73 | + @ConditionalOnProperty(name = "spring.modulith.events.jdbc.schema-initialization.enabled", havingValue = "true") |
| 74 | + static class NewPropertyEnabled {} |
| 75 | + } |
56 | 76 | } |
0 commit comments