Skip to content

Commit 72232ea

Browse files
committed
GH-3425: Remove mngmt gauges from CtxClosedEvent
Fixes #3425 It turns out that `IntegrationManagementConfigurer.destroy()` is still too late to remove `gauges` and Micrometer tries to gather them on application context close, when many beans are already destroyed * Catch `ContextClosedEvent` in the `IntegrationManagementConfigurer` and removed `gauges` from there * Remove `destroy()` impl since it is out of use already: the `IntegrationManagementConfigurer` is not supposed to be in the target application directly, so it looks safe to remove the `DisposableBean` altogether **Cherry-pick to `5.3.x` & `5.2.x`** # Conflicts: # spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfigurer.java
1 parent 927ba8f commit 72232ea

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfigurer.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828

2929
import org.springframework.beans.BeansException;
3030
import org.springframework.beans.factory.BeanNameAware;
31-
import org.springframework.beans.factory.DisposableBean;
3231
import org.springframework.beans.factory.SmartInitializingSingleton;
3332
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
3433
import org.springframework.context.ApplicationContext;
3534
import org.springframework.context.ApplicationContextAware;
35+
import org.springframework.context.ApplicationListener;
36+
import org.springframework.context.event.ContextClosedEvent;
3637
import org.springframework.integration.core.MessageSource;
3738
import org.springframework.integration.support.management.IntegrationManagement;
3839
import org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides;
@@ -61,7 +62,7 @@
6162
@SuppressWarnings("deprecation")
6263
public class IntegrationManagementConfigurer
6364
implements SmartInitializingSingleton, ApplicationContextAware, BeanNameAware,
64-
DestructionAwareBeanPostProcessor, DisposableBean {
65+
DestructionAwareBeanPostProcessor, ApplicationListener<ContextClosedEvent> {
6566

6667
private static final Log LOGGER = LogFactory.getLog(IntegrationManagementConfigurer.class);
6768

@@ -468,6 +469,13 @@ private void registerComponentGauges() {
468469
.build());
469470
}
470471

472+
@Override public void onApplicationEvent(ContextClosedEvent event) {
473+
if (event.getApplicationContext().equals(this.applicationContext)) {
474+
this.gauges.forEach(MeterFacade::remove);
475+
this.gauges.clear();
476+
}
477+
}
478+
471479
public String[] getChannelNames() {
472480
return this.channelsByName.keySet().toArray(new String[0]);
473481
}
@@ -518,13 +526,6 @@ public org.springframework.integration.support.management.MessageSourceMetrics g
518526
return null;
519527
}
520528

521-
@Override
522-
public void destroy() {
523-
this.gauges.forEach(MeterFacade::remove);
524-
this.gauges.clear();
525-
}
526-
527-
528529
private static ManagementOverrides getOverrides(IntegrationManagement bean) {
529530
return bean.getOverrides() != null ? bean.getOverrides() : new ManagementOverrides();
530531
}

0 commit comments

Comments
 (0)