|
28 | 28 |
|
29 | 29 | import org.springframework.beans.BeansException; |
30 | 30 | import org.springframework.beans.factory.BeanNameAware; |
| 31 | +import org.springframework.beans.factory.ObjectProvider; |
31 | 32 | import org.springframework.beans.factory.SmartInitializingSingleton; |
32 | 33 | import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; |
33 | 34 | import org.springframework.context.ApplicationContext; |
@@ -105,6 +106,8 @@ public class IntegrationManagementConfigurer |
105 | 106 |
|
106 | 107 | private MetricsCaptor metricsCaptor; |
107 | 108 |
|
| 109 | + private ObjectProvider<MetricsCaptor> metricsCaptorProvider; |
| 110 | + |
108 | 111 | @Override |
109 | 112 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
110 | 113 | this.applicationContext = applicationContext; |
@@ -251,12 +254,24 @@ public void setMetricsCaptor(@Nullable MetricsCaptor metricsCaptor) { |
251 | 254 | this.metricsCaptor = metricsCaptor; |
252 | 255 | } |
253 | 256 |
|
| 257 | + void setMetricsCaptorProvider(ObjectProvider<MetricsCaptor> metricsCaptorProvider) { |
| 258 | + this.metricsCaptorProvider = metricsCaptorProvider; |
| 259 | + } |
| 260 | + |
| 261 | + @Nullable |
| 262 | + MetricsCaptor obtainMetricsCaptor() { |
| 263 | + if (this.metricsCaptor == null && this.metricsCaptorProvider != null) { |
| 264 | + this.metricsCaptor = this.metricsCaptorProvider.getIfUnique(); |
| 265 | + } |
| 266 | + return this.metricsCaptor; |
| 267 | + } |
| 268 | + |
254 | 269 | @Override |
255 | 270 | public void afterSingletonsInstantiated() { |
256 | 271 | Assert.state(this.applicationContext != null, "'applicationContext' must not be null"); |
257 | 272 | Assert.state(MANAGEMENT_CONFIGURER_NAME.equals(this.beanName), getClass().getSimpleName() |
258 | 273 | + " bean name must be " + MANAGEMENT_CONFIGURER_NAME); |
259 | | - if (this.metricsCaptor != null) { |
| 274 | + if (obtainMetricsCaptor() != null) { |
260 | 275 | injectCaptor(); |
261 | 276 | registerComponentGauges(); |
262 | 277 | } |
@@ -305,7 +320,7 @@ private void injectCaptor() { |
305 | 320 | @Override |
306 | 321 | public Object postProcessAfterInitialization(Object bean, String name) throws BeansException { |
307 | 322 | if (this.singletonsInstantiated) { |
308 | | - if (this.metricsCaptor != null && bean instanceof IntegrationManagement) { |
| 323 | + if (obtainMetricsCaptor() != null && bean instanceof IntegrationManagement) { |
309 | 324 | ((IntegrationManagement) bean).registerMetricsCaptor(this.metricsCaptor); |
310 | 325 | } |
311 | 326 | return doConfigureMetrics(bean, name); |
|
0 commit comments