diff --git a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfiguration.java b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfiguration.java index a4823f10..8f71163b 100644 --- a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfiguration.java +++ b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfiguration.java @@ -139,7 +139,8 @@ public class LoadBalancerClientConfiguration { @ConditionalOnMissingBean @Conditional(WeightedConfigurationCondition.class) public ServiceInstanceListSupplier weightedServiceInstanceListSupplier(ConfigurableApplicationContext context) { - return ServiceInstanceListSupplier.builder().withDiscoveryClient().withWeighted().build(context); + return ServiceInstanceListSupplier.builder().withDiscoveryClient().withWeighted().withCaching() + .build(context); } } @@ -203,7 +204,8 @@ public class LoadBalancerClientConfiguration { @ConditionalOnMissingBean @Conditional(WeightedConfigurationCondition.class) public ServiceInstanceListSupplier weightedServiceInstanceListSupplier(ConfigurableApplicationContext context) { - return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().withWeighted().build(context); + return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().withWeighted().withCaching() + .build(context); } } diff --git a/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfigurationTests.java b/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfigurationTests.java index b13407fd..3e26296e 100644 --- a/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfigurationTests.java +++ b/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfigurationTests.java @@ -120,10 +120,13 @@ class LoadBalancerClientConfigurationTests { reactiveDiscoveryClientRunner.withUserConfiguration(TestConfig.class) .withPropertyValues("spring.cloud.loadbalancer.configurations=weighted").run(context -> { ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class); - then(supplier).isInstanceOf(WeightedServiceInstanceListSupplier.class); + then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class); ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier) .getDelegate(); - then(delegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class); + then(delegate).isInstanceOf(WeightedServiceInstanceListSupplier.class); + ServiceInstanceListSupplier secondDelegate = ((DelegatingServiceInstanceListSupplier) delegate) + .getDelegate(); + then(secondDelegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class); }); } @@ -204,8 +207,11 @@ class LoadBalancerClientConfigurationTests { blockingDiscoveryClientRunner.withUserConfiguration(RestTemplateTestConfig.class) .withPropertyValues("spring.cloud.loadbalancer.configurations=weighted").run(context -> { ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class); - then(supplier).isInstanceOf(WeightedServiceInstanceListSupplier.class); - then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate()) + then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class); + ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier) + .getDelegate(); + then(delegate).isInstanceOf(WeightedServiceInstanceListSupplier.class); + then(((DelegatingServiceInstanceListSupplier) delegate).getDelegate()) .isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class); }); }