Skip to content

Commit fce0fef

Browse files
artembilangaryrussell
authored andcommitted
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`**
1 parent 0331933 commit fce0fef

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323

2424
import org.springframework.beans.BeansException;
2525
import org.springframework.beans.factory.BeanNameAware;
26-
import org.springframework.beans.factory.DisposableBean;
2726
import org.springframework.beans.factory.SmartInitializingSingleton;
2827
import org.springframework.beans.factory.config.BeanPostProcessor;
2928
import org.springframework.context.ApplicationContext;
3029
import org.springframework.context.ApplicationContextAware;
30+
import org.springframework.context.ApplicationListener;
31+
import org.springframework.context.event.ContextClosedEvent;
3132
import org.springframework.integration.core.MessageSource;
3233
import org.springframework.integration.support.management.IntegrationManagement;
3334
import org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides;
@@ -53,7 +54,7 @@
5354
*/
5455
public class IntegrationManagementConfigurer
5556
implements SmartInitializingSingleton, ApplicationContextAware, BeanNameAware, BeanPostProcessor,
56-
DisposableBean {
57+
ApplicationListener<ContextClosedEvent> {
5758

5859
/**
5960
* Bean name of the configurer.
@@ -169,10 +170,11 @@ private void registerComponentGauges() {
169170
.build());
170171
}
171172

172-
@Override
173-
public void destroy() {
174-
this.gauges.forEach(MeterFacade::remove);
175-
this.gauges.clear();
173+
@Override public void onApplicationEvent(ContextClosedEvent event) {
174+
if (event.getApplicationContext().equals(this.applicationContext)) {
175+
this.gauges.forEach(MeterFacade::remove);
176+
this.gauges.clear();
177+
}
176178
}
177179

178180
private static ManagementOverrides getOverrides(IntegrationManagement bean) {

0 commit comments

Comments
 (0)