Browse Source

Moves conditional on class to class level

wip-poc-gh-595-power-of-two-loadbalancer
Spencer Gibb 5 years ago
parent
commit
6f83156c73
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 3
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/CommonsClientAutoConfiguration.java
  2. 2
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfiguration.java
  3. 24
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryClientAutoConfiguration.java
  4. 2
      spring-cloud-commons/src/test/java/org/springframework/cloud/client/CommonsClientAutoConfigurationTests.java
  5. 2
      spring-cloud-commons/src/test/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfigurationTests.java

3
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 { public class CommonsClientAutoConfiguration {
@Configuration @Configuration
@ConditionalOnClass(HealthIndicator.class)
@EnableConfigurationProperties(DiscoveryClientHealthIndicatorProperties.class) @EnableConfigurationProperties(DiscoveryClientHealthIndicatorProperties.class)
@ConditionalOnBean(DiscoveryClient.class) @ConditionalOnBean(DiscoveryClient.class)
@ConditionalOnDiscoveryEnabled @ConditionalOnDiscoveryEnabled
@ -59,7 +60,6 @@ public class CommonsClientAutoConfiguration {
protected static class DiscoveryLoadBalancerConfiguration { protected static class DiscoveryLoadBalancerConfiguration {
@Bean @Bean
@ConditionalOnClass(HealthIndicator.class)
@ConditionalOnDiscoveryHealthIndicatorEnabled @ConditionalOnDiscoveryHealthIndicatorEnabled
public DiscoveryClientHealthIndicator discoveryClientHealthIndicator( public DiscoveryClientHealthIndicator discoveryClientHealthIndicator(
ObjectProvider<DiscoveryClient> discoveryClient, ObjectProvider<DiscoveryClient> discoveryClient,
@ -68,7 +68,6 @@ public class CommonsClientAutoConfiguration {
} }
@Bean @Bean
@ConditionalOnClass(HealthIndicator.class)
@ConditionalOnProperty( @ConditionalOnProperty(
value = "spring.cloud.discovery.client.composite-indicator.enabled", value = "spring.cloud.discovery.client.composite-indicator.enabled",
matchIfMissing = true) matchIfMissing = true)

2
spring-cloud-commons/src/main/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfiguration.java

@ -45,13 +45,13 @@ public class ReactiveCommonsClientAutoConfiguration {
@Configuration @Configuration
@EnableConfigurationProperties(DiscoveryClientHealthIndicatorProperties.class) @EnableConfigurationProperties(DiscoveryClientHealthIndicatorProperties.class)
@ConditionalOnClass(ReactiveHealthIndicator.class)
@ConditionalOnBean(ReactiveDiscoveryClient.class) @ConditionalOnBean(ReactiveDiscoveryClient.class)
@ConditionalOnDiscoveryEnabled @ConditionalOnDiscoveryEnabled
@ConditionalOnReactiveDiscoveryEnabled @ConditionalOnReactiveDiscoveryEnabled
protected static class ReactiveDiscoveryLoadBalancerConfiguration { protected static class ReactiveDiscoveryLoadBalancerConfiguration {
@Bean @Bean
@ConditionalOnClass(ReactiveHealthIndicator.class)
@ConditionalOnProperty( @ConditionalOnProperty(
value = "spring.cloud.discovery.client.composite-indicator.enabled", value = "spring.cloud.discovery.client.composite-indicator.enabled",
matchIfMissing = true) matchIfMissing = true)

24
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()); return new SimpleReactiveDiscoveryClient(simpleReactiveDiscoveryProperties());
} }
@Bean
@ConditionalOnClass(ReactiveHealthIndicator.class)
@ConditionalOnDiscoveryHealthIndicatorEnabled
public ReactiveDiscoveryClientHealthIndicator simpleReactiveDiscoveryClientHealthIndicator(
DiscoveryClientHealthIndicatorProperties properties) {
return new ReactiveDiscoveryClientHealthIndicator(simpleReactiveDiscoveryClient(),
properties);
}
private int findPort() { private int findPort() {
if (port > 0) { if (port > 0) {
return port; 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);
}
}
} }

2
spring-cloud-commons/src/test/java/org/springframework/cloud/client/CommonsClientAutoConfigurationTests.java

@ -126,7 +126,7 @@ public class CommonsClientAutoConfigurationTests {
.doesNotHaveBean(DiscoveryClientHealthIndicator.class); .doesNotHaveBean(DiscoveryClientHealthIndicator.class);
assertThat(context) assertThat(context)
.doesNotHaveBean(DiscoveryCompositeHealthIndicator.class); .doesNotHaveBean(DiscoveryCompositeHealthIndicator.class);
then(context.getBeansOfType(HasFeatures.class).values()).isNotEmpty(); then(context.getBeansOfType(HasFeatures.class).values()).isEmpty();
}); });
} }

2
spring-cloud-commons/src/test/java/org/springframework/cloud/client/ReactiveCommonsClientAutoConfigurationTests.java

@ -123,7 +123,7 @@ public class ReactiveCommonsClientAutoConfigurationTests {
ReactiveDiscoveryClientHealthIndicator.class); ReactiveDiscoveryClientHealthIndicator.class);
assertThat(context).doesNotHaveBean( assertThat(context).doesNotHaveBean(
ReactiveDiscoveryCompositeHealthContributor.class); ReactiveDiscoveryCompositeHealthContributor.class);
then(context.getBeansOfType(HasFeatures.class).values()).isNotEmpty(); then(context.getBeansOfType(HasFeatures.class).values()).isEmpty();
}); });
} }

Loading…
Cancel
Save