|
15 | 15 | */
|
16 | 16 | package org.springframework.modulith.events.jdbc;
|
17 | 17 |
|
| 18 | +import java.util.List; |
| 19 | + |
18 | 20 | import javax.sql.DataSource;
|
19 | 21 |
|
20 |
| -import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; |
21 |
| -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 22 | +import org.springframework.boot.autoconfigure.condition.ConditionOutcome; |
| 23 | +import org.springframework.boot.autoconfigure.condition.SpringBootCondition; |
22 | 24 | import org.springframework.boot.jdbc.DatabaseDriver;
|
23 | 25 | import org.springframework.context.annotation.Bean;
|
| 26 | +import org.springframework.context.annotation.ConditionContext; |
24 | 27 | import org.springframework.context.annotation.Conditional;
|
25 | 28 | import org.springframework.context.annotation.Configuration;
|
| 29 | +import org.springframework.core.env.Environment; |
26 | 30 | import org.springframework.core.io.ResourceLoader;
|
| 31 | +import org.springframework.core.type.AnnotatedTypeMetadata; |
27 | 32 | import org.springframework.jdbc.core.JdbcTemplate;
|
28 | 33 | import org.springframework.modulith.events.EventSerializer;
|
29 | 34 | import org.springframework.modulith.events.config.EventPublicationConfigurationExtension;
|
@@ -61,16 +66,27 @@ DatabaseSchemaInitializer databaseSchemaInitializer(JdbcTemplate jdbcTemplate, R
|
61 | 66 | *
|
62 | 67 | * @author Oliver Drotbohm
|
63 | 68 | */
|
64 |
| - static class SchemaInitializationEnabled extends AnyNestedCondition { |
| 69 | + static class SchemaInitializationEnabled extends SpringBootCondition { |
65 | 70 |
|
66 |
| - public SchemaInitializationEnabled() { |
67 |
| - super(ConfigurationPhase.PARSE_CONFIGURATION); |
68 |
| - } |
| 71 | + private static final String LEGACY = "spring.modulith.events.jdbc-schema-initialization.enabled"; |
| 72 | + private static final String CURRENT = "spring.modulith.events.jdbc.schema-initialization.enabled"; |
| 73 | + |
| 74 | + /* |
| 75 | + * (non-Javadoc) |
| 76 | + * @see org.springframework.boot.autoconfigure.condition.SpringBootCondition#getMatchOutcome(org.springframework.context.annotation.ConditionContext, org.springframework.core.type.AnnotatedTypeMetadata) |
| 77 | + */ |
| 78 | + @Override |
| 79 | + public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { |
69 | 80 |
|
70 |
| - @ConditionalOnProperty(name = "spring.modulith.events.jdbc-schema-initialization.enabled", havingValue = "true") |
71 |
| - static class LegacyPropertyEnabled {} |
| 81 | + Environment environment = context.getEnvironment(); |
72 | 82 |
|
73 |
| - @ConditionalOnProperty(name = "spring.modulith.events.jdbc.schema-initialization.enabled", havingValue = "true") |
74 |
| - static class NewPropertyEnabled {} |
| 83 | + var enabled = List.of(CURRENT, LEGACY).stream() |
| 84 | + .map(it -> environment.getProperty(it, Boolean.class)) |
| 85 | + .anyMatch(Boolean.TRUE::equals); |
| 86 | + |
| 87 | + return enabled // |
| 88 | + ? ConditionOutcome.match("Schema initialization explicitly enabled.") // |
| 89 | + : ConditionOutcome.noMatch("Schema initialization disabled by default."); |
| 90 | + } |
75 | 91 | }
|
76 | 92 | }
|
0 commit comments