diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/SimpleObjectProvider.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/SimpleObjectProvider.java deleted file mode 100644 index b12ce977..00000000 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/SimpleObjectProvider.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2024 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; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerWebClientBuilderBeanPostProcessor; - -/** - * Wrapper for {@link ObjectProvider}. Added to use for a workaround in - * {@link LoadBalancerWebClientBuilderBeanPostProcessor}. - * - * @param type of the object to fetch - * @author Spencer Gibb - * @deprecated for removal in 4.0 - */ -@Deprecated(forRemoval = true) -public class SimpleObjectProvider implements ObjectProvider { - - private final T object; - - public SimpleObjectProvider(T object) { - this.object = object; - } - - @Override - public T getObject(Object... args) throws BeansException { - return this.object; - } - - @Override - public T getIfAvailable() throws BeansException { - return this.object; - } - - @Override - public T getIfUnique() throws BeansException { - return this.object; - } - - @Override - public T getObject() throws BeansException { - return this.object; - } - -} diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/DeferringLoadBalancerExchangeFilterFunction.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/DeferringLoadBalancerExchangeFilterFunction.java index d370b981..4e419770 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/DeferringLoadBalancerExchangeFilterFunction.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/DeferringLoadBalancerExchangeFilterFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2020 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. @@ -55,7 +55,7 @@ public class DeferringLoadBalancerExchangeFilterFunction deferringExchangeFilterFunction, + @Lazy DeferringLoadBalancerExchangeFilterFunction deferringExchangeFilterFunction, ApplicationContext context) { return new LoadBalancerWebClientBuilderBeanPostProcessor(deferringExchangeFilterFunction, context); } diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerWebClientBuilderBeanPostProcessor.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerWebClientBuilderBeanPostProcessor.java index e07f9590..bb8db3ff 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerWebClientBuilderBeanPostProcessor.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/LoadBalancerWebClientBuilderBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2020 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. @@ -17,10 +17,8 @@ package org.springframework.cloud.client.loadbalancer.reactive; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.cloud.client.loadbalancer.LoadBalanced; -import org.springframework.cloud.client.loadbalancer.SimpleObjectProvider; import org.springframework.context.ApplicationContext; import org.springframework.web.reactive.function.client.WebClient; @@ -32,28 +30,15 @@ import org.springframework.web.reactive.function.client.WebClient; * @author Olga Maciaszek-Sharma * @since 2.2.0 */ -@SuppressWarnings({ "removal", "rawtypes" }) public class LoadBalancerWebClientBuilderBeanPostProcessor implements BeanPostProcessor { - private final ObjectProvider exchangeFilterFunctionObjectProvider; + private final DeferringLoadBalancerExchangeFilterFunction exchangeFilterFunction; private final ApplicationContext context; - /** - * @deprecated in favour of - * {@link LoadBalancerWebClientBuilderBeanPostProcessor#LoadBalancerWebClientBuilderBeanPostProcessor(ObjectProvider, ApplicationContext)} - */ - @Deprecated(forRemoval = true) public LoadBalancerWebClientBuilderBeanPostProcessor( DeferringLoadBalancerExchangeFilterFunction exchangeFilterFunction, ApplicationContext context) { - this.exchangeFilterFunctionObjectProvider = new SimpleObjectProvider<>(exchangeFilterFunction); - this.context = context; - } - - public LoadBalancerWebClientBuilderBeanPostProcessor( - ObjectProvider exchangeFilterFunction, - ApplicationContext context) { - this.exchangeFilterFunctionObjectProvider = exchangeFilterFunction; + this.exchangeFilterFunction = exchangeFilterFunction; this.context = context; } @@ -63,12 +48,7 @@ public class LoadBalancerWebClientBuilderBeanPostProcessor implements BeanPostPr if (context.findAnnotationOnBean(beanName, LoadBalanced.class) == null) { return bean; } - DeferringLoadBalancerExchangeFilterFunction exchangeFilterFunction = exchangeFilterFunctionObjectProvider - .getIfAvailable(); - if (exchangeFilterFunction == null) { - throw new IllegalStateException("LoadBalancerExchangeFilterFunction not found"); - } - ((WebClient.Builder) bean).filter(exchangeFilterFunctionObjectProvider.getIfAvailable()); + ((WebClient.Builder) bean).filter(exchangeFilterFunction); } return bean; }