diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfiguration.java index 949db76c16..4be11e03e6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ import org.springframework.context.annotation.Configuration; @AutoConfigureAfter({ MetricsAutoConfiguration.class, RabbitAutoConfiguration.class, SimpleMetricsExportAutoConfiguration.class }) @ConditionalOnClass({ ConnectionFactory.class, AbstractConnectionFactory.class }) -@ConditionalOnBean({ AbstractConnectionFactory.class, MeterRegistry.class }) +@ConditionalOnBean({ org.springframework.amqp.rabbit.connection.ConnectionFactory.class, MeterRegistry.class }) public class RabbitMetricsAutoConfiguration { @Bean diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfigurationTests.java index 1e218923f5..dd2c9931a3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,14 @@ package org.springframework.boot.actuate.autoconfigure.metrics.amqp; import io.micrometer.core.instrument.MeterRegistry; import org.junit.jupiter.api.Test; +import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; @@ -45,6 +49,15 @@ class RabbitMetricsAutoConfigurationTests { }); } + @Test + void abstractConnectionFactoryDefinedAsAConnectionFactoryIsInstrumented() { + this.contextRunner.withUserConfiguration(ConnectionFactoryConfiguration.class).run((context) -> { + assertThat(context).hasBean("customConnectionFactory"); + MeterRegistry registry = context.getBean(MeterRegistry.class); + registry.get("rabbitmq.connections").meter(); + }); + } + @Test void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() { this.contextRunner.withPropertyValues("management.metrics.enable.rabbitmq=false").run((context) -> { @@ -53,4 +66,14 @@ class RabbitMetricsAutoConfigurationTests { }); } + @Configuration + static class ConnectionFactoryConfiguration { + + @Bean + ConnectionFactory customConnectionFactory() { + return new CachingConnectionFactory(); + } + + } + }