From 62f9d76127ca0bfb8f195b8d4acd7cfa5dc1f73e Mon Sep 17 00:00:00 2001 From: spencergibb Date: Mon, 28 Nov 2022 12:43:22 -0500 Subject: [PATCH] Moves ConditionalOnClass to static class --- .../cloud/openfeign/FeignClientsConfiguration.java | 3 +-- .../FeignClientsMicrometerAutoConfigurationTests.java | 9 ++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java index aa9dd2ac..3372a0c5 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java @@ -238,19 +238,18 @@ public class FeignClientsConfiguration { @Configuration(proxyBeanMethods = false) @ConditionalOnProperty(name = "spring.cloud.openfeign.micrometer.enabled", matchIfMissing = true) + @ConditionalOnClass({ MicrometerObservationCapability.class, MicrometerCapability.class, MeterRegistry.class }) @Conditional(FeignClientMicrometerEnabledCondition.class) protected static class MicrometerConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnClass(name = "feign.micrometer.MicrometerObservationCapability") @ConditionalOnBean(type = "io.micrometer.observation.ObservationRegistry") public MicrometerObservationCapability micrometerObservationCapability(ObservationRegistry registry) { return new MicrometerObservationCapability(registry); } @Bean - @ConditionalOnClass(name = "feign.micrometer.MicrometerCapability") @ConditionalOnBean(type = "io.micrometer.core.instrument.MeterRegistry") @ConditionalOnMissingBean({ MicrometerCapability.class, MicrometerObservationCapability.class }) public MicrometerCapability micrometerCapability(MeterRegistry registry) { diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsMicrometerAutoConfigurationTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsMicrometerAutoConfigurationTests.java index 165ec71c..2218fbba 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsMicrometerAutoConfigurationTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsMicrometerAutoConfigurationTests.java @@ -63,15 +63,14 @@ class FeignClientsMicrometerAutoConfigurationTests { } @Test - void shouldProvideMicrometerCapabilityIfMicrometerObservationCapabilityIsNotOnClasspath() { - contextRunner.withClassLoader(new FilteredClassLoader(MicrometerObservationCapability.class)) - .run(context -> assertThat(context).doesNotHaveBean(MicrometerObservationCapability.class) - .hasSingleBean(MicrometerCapability.class)); + void shouldNotProvideMicrometerCapabilitiesIfFeignMicrometerSupportIsMissing() { + contextRunner.withClassLoader(new FilteredClassLoader("feign.micrometer")).run(context -> assertThat(context) + .doesNotHaveBean(MicrometerObservationCapability.class).doesNotHaveBean(MicrometerCapability.class)); } @Test void shouldNotProvideMicrometerCapabilitiesIfMicrometerSupportIsMissing() { - contextRunner.withClassLoader(new FilteredClassLoader("feign.micrometer")).run(context -> assertThat(context) + contextRunner.withClassLoader(new FilteredClassLoader("io.micrometer")).run(context -> assertThat(context) .doesNotHaveBean(MicrometerObservationCapability.class).doesNotHaveBean(MicrometerCapability.class)); }