|
24 | 24 | import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
|
25 | 25 | import org.springframework.boot.actuate.autoconfigure.info.InfoEndpointAutoConfiguration;
|
26 | 26 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
| 27 | +import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; |
| 28 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
27 | 29 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
28 | 30 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
29 | 31 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
36 | 38 | import org.springframework.cloud.kubernetes.config.SecretsPropertySourceLocator;
|
37 | 39 | import org.springframework.context.ConfigurableApplicationContext;
|
38 | 40 | import org.springframework.context.annotation.Bean;
|
| 41 | +import org.springframework.context.annotation.Conditional; |
39 | 42 | import org.springframework.context.annotation.Configuration;
|
40 | 43 | import org.springframework.core.env.AbstractEnvironment;
|
41 | 44 | import org.springframework.scheduling.annotation.EnableAsync;
|
@@ -71,28 +74,24 @@ protected static class ConfigReloadAutoConfigurationBeans {
|
71 | 74 | @Autowired
|
72 | 75 | private KubernetesClient kubernetesClient;
|
73 | 76 |
|
74 |
| - @Autowired |
75 |
| - private ConfigMapPropertySourceLocator configMapPropertySourceLocator; |
76 |
| - |
77 |
| - @Autowired |
78 |
| - private SecretsPropertySourceLocator secretsPropertySourceLocator; |
79 |
| - |
80 | 77 | /**
|
81 | 78 | * @param properties config reload properties
|
82 | 79 | * @param strategy configuration update strategy
|
83 | 80 | * @return a bean that listen to configuration changes and fire a reload.
|
84 | 81 | */
|
85 | 82 | @Bean
|
86 |
| - @ConditionalOnMissingBean |
| 83 | + @Conditional(OnConfigEnabledOrSecretsEnabled.class) |
87 | 84 | public ConfigurationChangeDetector propertyChangeWatcher(ConfigReloadProperties properties,
|
88 |
| - ConfigurationUpdateStrategy strategy) { |
| 85 | + ConfigurationUpdateStrategy strategy, |
| 86 | + @Autowired(required = false) ConfigMapPropertySourceLocator configMapPropertySourceLocator, |
| 87 | + @Autowired(required = false) SecretsPropertySourceLocator secretsPropertySourceLocator) { |
89 | 88 | switch (properties.getMode()) {
|
90 | 89 | case POLLING:
|
91 | 90 | return new PollingConfigurationChangeDetector(this.environment, properties, this.kubernetesClient,
|
92 |
| - strategy, this.configMapPropertySourceLocator, this.secretsPropertySourceLocator); |
| 91 | + strategy, configMapPropertySourceLocator, secretsPropertySourceLocator); |
93 | 92 | case EVENT:
|
94 | 93 | return new EventBasedConfigurationChangeDetector(this.environment, properties, this.kubernetesClient,
|
95 |
| - strategy, this.configMapPropertySourceLocator, this.secretsPropertySourceLocator); |
| 94 | + strategy, configMapPropertySourceLocator, secretsPropertySourceLocator); |
96 | 95 | }
|
97 | 96 | throw new IllegalStateException("Unsupported configuration reload mode: " + properties.getMode());
|
98 | 97 | }
|
@@ -136,6 +135,24 @@ private static void wait(ConfigReloadProperties properties) {
|
136 | 135 | }
|
137 | 136 | }
|
138 | 137 |
|
| 138 | + private static class OnConfigEnabledOrSecretsEnabled extends AnyNestedCondition { |
| 139 | + |
| 140 | + OnConfigEnabledOrSecretsEnabled() { |
| 141 | + super(ConfigurationPhase.REGISTER_BEAN); |
| 142 | + } |
| 143 | + |
| 144 | + @ConditionalOnBean(ConfigMapPropertySourceLocator.class) |
| 145 | + static class configEnabled { |
| 146 | + |
| 147 | + } |
| 148 | + |
| 149 | + @ConditionalOnBean(SecretsPropertySourceLocator.class) |
| 150 | + static class secretsEnabled { |
| 151 | + |
| 152 | + } |
| 153 | + |
| 154 | + } |
| 155 | + |
139 | 156 | }
|
140 | 157 |
|
141 | 158 | }
|
0 commit comments