Hello!

It seems that the newly introduced RepositoryMetricsAutoConfiguration (Spring Boot 2.5.0) triggers the creation of the MeterRegistry bean during the initialization of the bean post processor. This leaves no chance for MeterRegistryPostProcessor#postProcessAfterInitialization to customize the registry with MeterRegistryCustomizer. The call stack shows some registerBeanPostProcessors when the registry is instanciated which is not the case when RepositoryMetricsAutoConfiguration is not loaded.

I created a minimal sample repo to reproduce the issue.

If you run it, you can see that MetricsCustomizerNotCalledApplication#meterRegistryCustomizer is never called. If spring-boot-starter-data-jpa is removed from dependencies, it is called as expected.

A ugly workaround would be to call it again afterwards with something like:

    @Bean
    public InitializingBean forceMeterPostProcessor(BeanPostProcessor meterRegistryPostProcessor, MeterRegistry registry) {

        return () -> meterRegistryPostProcessor.postProcessAfterInitialization(registry, "");
    }

Thanks for your help.

Comment From: izeye

This seems to be a duplicate of https://github.com/spring-projects/spring-boot/issues/26630.

Comment From: scottfrederick

Running the sample against Spring Boot 2.5.1-SNAPSHOT results in the expected message being shown. Marking as duplicate of #26630.