|
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; |
@@ -108,6 +109,8 @@ public class IntegrationManagementConfigurer |
108 | 109 |
|
109 | 110 | private MetricsCaptor metricsCaptor; |
110 | 111 |
|
| 112 | + private ObjectProvider<MetricsCaptor> metricsCaptorProvider; |
| 113 | + |
111 | 114 | @Override |
112 | 115 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
113 | 116 | this.applicationContext = applicationContext; |
@@ -254,12 +257,24 @@ public void setMetricsCaptor(@Nullable MetricsCaptor metricsCaptor) { |
254 | 257 | this.metricsCaptor = metricsCaptor; |
255 | 258 | } |
256 | 259 |
|
| 260 | + void setMetricsCaptorProvider(ObjectProvider<MetricsCaptor> metricsCaptorProvider) { |
| 261 | + this.metricsCaptorProvider = metricsCaptorProvider; |
| 262 | + } |
| 263 | + |
| 264 | + @Nullable |
| 265 | + MetricsCaptor obtainMetricsCaptor() { |
| 266 | + if (this.metricsCaptor == null && this.metricsCaptorProvider != null) { |
| 267 | + this.metricsCaptor = this.metricsCaptorProvider.getIfUnique(); |
| 268 | + } |
| 269 | + return this.metricsCaptor; |
| 270 | + } |
| 271 | + |
257 | 272 | @Override |
258 | 273 | public void afterSingletonsInstantiated() { |
259 | 274 | Assert.state(this.applicationContext != null, "'applicationContext' must not be null"); |
260 | 275 | Assert.state(MANAGEMENT_CONFIGURER_NAME.equals(this.beanName), getClass().getSimpleName() |
261 | 276 | + " bean name must be " + MANAGEMENT_CONFIGURER_NAME); |
262 | | - if (this.metricsCaptor != null) { |
| 277 | + if (obtainMetricsCaptor() != null) { |
263 | 278 | injectCaptor(); |
264 | 279 | registerComponentGauges(); |
265 | 280 | } |
@@ -308,7 +323,7 @@ private void injectCaptor() { |
308 | 323 | @Override |
309 | 324 | public Object postProcessAfterInitialization(Object bean, String name) throws BeansException { |
310 | 325 | if (this.singletonsInstantiated) { |
311 | | - if (this.metricsCaptor != null && bean instanceof IntegrationManagement) { |
| 326 | + if (obtainMetricsCaptor() != null && bean instanceof IntegrationManagement) { |
312 | 327 | ((IntegrationManagement) bean).registerMetricsCaptor(this.metricsCaptor); |
313 | 328 | } |
314 | 329 | return doConfigureMetrics(bean, name); |
|
0 commit comments