diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerBeanPostProcessorAutoConfiguration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerBeanPostProcessorAutoConfiguration.java index 98aba0fa..589a2225 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerBeanPostProcessorAutoConfiguration.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerBeanPostProcessorAutoConfiguration.java @@ -57,7 +57,7 @@ public class LoadBalancerBeanPostProcessorAutoConfiguration { } @Configuration(proxyBeanMethods = false) - @Conditional(ReactorLoadBalancerClientAutoConfiguration.OnNoRibbonDefaultCondition.class) + @Conditional(OnNoRibbonDefaultCondition.class) @ConditionalOnBean(ReactiveLoadBalancer.Factory.class) protected static class ReactorDeferringLoadBalancerFilterConfig { diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/OnNoRibbonDefaultCondition.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/OnNoRibbonDefaultCondition.java new file mode 100644 index 00000000..7225298f --- /dev/null +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/OnNoRibbonDefaultCondition.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.client.loadbalancer.reactive; + +import java.util.concurrent.locks.Condition; + +import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; + +/** + * A {@link Condition} that verifies that Ribbon is either not present or disabled. + * + * @author Olga Maciaszek-Sharma + * @since 2.2.1 + */ +public class OnNoRibbonDefaultCondition extends AnyNestedCondition { + + public OnNoRibbonDefaultCondition() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnProperty(value = "spring.cloud.loadbalancer.ribbon.enabled", + havingValue = "false") + static class RibbonNotEnabled { + + } + + @ConditionalOnMissingClass("org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient") + static class RibbonLoadBalancerNotPresent { + + } + +} diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/ReactorLoadBalancerClientAutoConfiguration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/ReactorLoadBalancerClientAutoConfiguration.java index 4c09b7f9..4c1930e9 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/ReactorLoadBalancerClientAutoConfiguration.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/ReactorLoadBalancerClientAutoConfiguration.java @@ -21,10 +21,8 @@ import javax.annotation.PostConstruct; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; @@ -66,25 +64,6 @@ public class ReactorLoadBalancerClientAutoConfiguration { } - static final class OnNoRibbonDefaultCondition extends AnyNestedCondition { - - private OnNoRibbonDefaultCondition() { - super(ConfigurationPhase.REGISTER_BEAN); - } - - @ConditionalOnProperty(value = "spring.cloud.loadbalancer.ribbon.enabled", - havingValue = "false") - static class RibbonNotEnabled { - - } - - @ConditionalOnMissingClass("org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient") - static class RibbonLoadBalancerNotPresent { - - } - - } - private static class ReactorLoadBalancerClientRibbonWarnLogger { private static final Log LOG = LogFactory diff --git a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/config/BlockingLoadBalancerClientAutoConfiguration.java b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/config/BlockingLoadBalancerClientAutoConfiguration.java index 95fb15eb..97c72c21 100644 --- a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/config/BlockingLoadBalancerClientAutoConfiguration.java +++ b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/config/BlockingLoadBalancerClientAutoConfiguration.java @@ -23,12 +23,11 @@ import org.apache.commons.logging.LogFactory; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.client.loadbalancer.AsyncLoadBalancerAutoConfiguration; +import org.springframework.cloud.client.loadbalancer.reactive.OnNoRibbonDefaultCondition; import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients; import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient; import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; @@ -76,25 +75,6 @@ public class BlockingLoadBalancerClientAutoConfiguration { } - private static final class OnNoRibbonDefaultCondition extends AnyNestedCondition { - - private OnNoRibbonDefaultCondition() { - super(ConfigurationPhase.REGISTER_BEAN); - } - - @ConditionalOnProperty(value = "spring.cloud.loadbalancer.ribbon.enabled", - havingValue = "false") - static class RibbonNotEnabled { - - } - - @ConditionalOnMissingClass("org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient") - static class RibbonLoadBalancerNotPresent { - - } - - } - static class BlockingLoadBalancerClientRibbonWarnLogger { private static final Log LOG = LogFactory diff --git a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/config/LoadBalancerCacheAutoConfiguration.java b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/config/LoadBalancerCacheAutoConfiguration.java index 78a425b6..cd610098 100644 --- a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/config/LoadBalancerCacheAutoConfiguration.java +++ b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/config/LoadBalancerCacheAutoConfiguration.java @@ -32,11 +32,13 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cache.CacheManager; import org.springframework.cache.interceptor.CacheAspectSupport; +import org.springframework.cloud.client.loadbalancer.reactive.OnNoRibbonDefaultCondition; import org.springframework.cloud.loadbalancer.cache.CaffeineBasedLoadBalancerCacheManager; import org.springframework.cloud.loadbalancer.cache.DefaultLoadBalancerCacheManager; import org.springframework.cloud.loadbalancer.cache.LoadBalancerCacheManager; import org.springframework.cloud.loadbalancer.cache.LoadBalancerCacheProperties; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; /** @@ -57,6 +59,7 @@ import org.springframework.context.annotation.Configuration; @ConditionalOnProperty(value = "spring.cloud.loadbalancer.cache.enabled", matchIfMissing = true) @EnableConfigurationProperties(LoadBalancerCacheProperties.class) +@Conditional(OnNoRibbonDefaultCondition.class) public class LoadBalancerCacheAutoConfiguration { @Configuration(proxyBeanMethods = false)