diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java index 2c6b32a2..bb826397 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java @@ -52,6 +52,7 @@ import org.springframework.context.annotation.Configuration; public class CommonsClientAutoConfiguration { @Configuration + @ConditionalOnClass(HealthIndicator.class) @EnableConfigurationProperties(DiscoveryClientHealthIndicatorProperties.class) @ConditionalOnBean(DiscoveryClient.class) @ConditionalOnDiscoveryEnabled @@ -59,7 +60,6 @@ public class CommonsClientAutoConfiguration { protected static class DiscoveryLoadBalancerConfiguration { @Bean - @ConditionalOnClass(HealthIndicator.class) @ConditionalOnDiscoveryHealthIndicatorEnabled public DiscoveryClientHealthIndicator discoveryClientHealthIndicator( ObjectProvider discoveryClient, @@ -68,7 +68,6 @@ public class CommonsClientAutoConfiguration { } @Bean - @ConditionalOnClass(HealthIndicator.class) @ConditionalOnProperty( value = "spring.cloud.discovery.client.composite-indicator.enabled", matchIfMissing = true) diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfiguration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfiguration.java index dbaad4cf..f3902ff3 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfiguration.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfiguration.java @@ -45,13 +45,13 @@ public class ReactiveCommonsClientAutoConfiguration { @Configuration @EnableConfigurationProperties(DiscoveryClientHealthIndicatorProperties.class) + @ConditionalOnClass(ReactiveHealthIndicator.class) @ConditionalOnBean(ReactiveDiscoveryClient.class) @ConditionalOnDiscoveryEnabled @ConditionalOnReactiveDiscoveryEnabled protected static class ReactiveDiscoveryLoadBalancerConfiguration { @Bean - @ConditionalOnClass(ReactiveHealthIndicator.class) @ConditionalOnProperty( value = "spring.cloud.discovery.client.composite-indicator.enabled", matchIfMissing = true) diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryClientAutoConfiguration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryClientAutoConfiguration.java index 2b56f86e..23f9164f 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryClientAutoConfiguration.java @@ -82,15 +82,6 @@ public class SimpleReactiveDiscoveryClientAutoConfiguration return new SimpleReactiveDiscoveryClient(simpleReactiveDiscoveryProperties()); } - @Bean - @ConditionalOnClass(ReactiveHealthIndicator.class) - @ConditionalOnDiscoveryHealthIndicatorEnabled - public ReactiveDiscoveryClientHealthIndicator simpleReactiveDiscoveryClientHealthIndicator( - DiscoveryClientHealthIndicatorProperties properties) { - return new ReactiveDiscoveryClientHealthIndicator(simpleReactiveDiscoveryClient(), - properties); - } - private int findPort() { if (port > 0) { return port; @@ -110,4 +101,19 @@ public class SimpleReactiveDiscoveryClientAutoConfiguration } } + @Configuration + @ConditionalOnClass(ReactiveHealthIndicator.class) + protected static class HealthConfiguration { + + @Bean + @ConditionalOnDiscoveryHealthIndicatorEnabled + public ReactiveDiscoveryClientHealthIndicator simpleReactiveDiscoveryClientHealthIndicator( + DiscoveryClientHealthIndicatorProperties properties, + SimpleReactiveDiscoveryClient simpleReactiveDiscoveryClient) { + return new ReactiveDiscoveryClientHealthIndicator( + simpleReactiveDiscoveryClient, properties); + } + + } + } diff --git a/spring-cloud-commons/src/test/java/org/springframework/cloud/client/CommonsClientAutoConfigurationTests.java b/spring-cloud-commons/src/test/java/org/springframework/cloud/client/CommonsClientAutoConfigurationTests.java index 5176d2ab..4add212a 100644 --- a/spring-cloud-commons/src/test/java/org/springframework/cloud/client/CommonsClientAutoConfigurationTests.java +++ b/spring-cloud-commons/src/test/java/org/springframework/cloud/client/CommonsClientAutoConfigurationTests.java @@ -126,7 +126,7 @@ public class CommonsClientAutoConfigurationTests { .doesNotHaveBean(DiscoveryClientHealthIndicator.class); assertThat(context) .doesNotHaveBean(DiscoveryCompositeHealthIndicator.class); - then(context.getBeansOfType(HasFeatures.class).values()).isNotEmpty(); + then(context.getBeansOfType(HasFeatures.class).values()).isEmpty(); }); } diff --git a/spring-cloud-commons/src/test/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfigurationTests.java b/spring-cloud-commons/src/test/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfigurationTests.java index 3dea6b9f..46062f3d 100644 --- a/spring-cloud-commons/src/test/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfigurationTests.java +++ b/spring-cloud-commons/src/test/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfigurationTests.java @@ -123,7 +123,7 @@ public class ReactiveCommonsClientAutoConfigurationTests { ReactiveDiscoveryClientHealthIndicator.class); assertThat(context).doesNotHaveBean( ReactiveDiscoveryCompositeHealthContributor.class); - then(context.getBeansOfType(HasFeatures.class).values()).isNotEmpty(); + then(context.getBeansOfType(HasFeatures.class).values()).isEmpty(); }); }