Parent's MeterRegistry beans are closed when child context closes by berry120 · Pull Request #48319 · spring-projects/spring-boot

MetricsAutoConfiguration contains a MeterRegistryCloser that ensures MeterRegistry instances are closed early in the shutdown process. However, this currently works by closing all such instances when any application context is closed. In the case where a child application context is created and then closed but the application is still running (i.e. the root context hasn't closed), the closure of this child context will then close all MeterRegistry instances prematurely.

(As a real-world example - when using the initializr library and calling ProjectGenerationInvoker.invokeProjectStructureGeneration, a ProjectGenerationContext is created, and then closed before the method returns - this then closes all the MeterRegistry instances defined in the application calling the initializr library.)

This fix ensures that the closure only happens when the root application context is being closed.

(I believe this is my first PR here, so happy to correct anything I may have done wrong!)