diff --git a/module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/autoconfigure/service/ConditionalOnMissingHttpServiceProxyBean.java b/module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/autoconfigure/service/ConditionalOnMissingHttpServiceProxyBean.java deleted file mode 100644 index f973e0325fe..00000000000 --- a/module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/autoconfigure/service/ConditionalOnMissingHttpServiceProxyBean.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-present 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.boot.http.client.autoconfigure.service; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.springframework.context.annotation.Conditional; - -/** - * {@link Conditional @Conditional} that matches when one or more HTTP Service bean has - * been registered. - * - * @author Phillip Webb - * @since 4.0.0 - */ -@Target({ ElementType.TYPE, ElementType.METHOD }) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Conditional(OnMissingHttpServiceProxyBeanCondition.class) -public @interface ConditionalOnMissingHttpServiceProxyBean { - -} diff --git a/module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/autoconfigure/service/OnMissingHttpServiceProxyBeanCondition.java b/module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/autoconfigure/service/OnMissingHttpServiceProxyBeanCondition.java deleted file mode 100644 index 146162b1571..00000000000 --- a/module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/autoconfigure/service/OnMissingHttpServiceProxyBeanCondition.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2012-present 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.boot.http.client.autoconfigure.service; - -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.HierarchicalBeanFactory; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; -import org.springframework.boot.autoconfigure.condition.ConditionalOnJava; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.context.annotation.Condition; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.context.annotation.ConfigurationCondition; -import org.springframework.core.type.AnnotatedTypeMetadata; - -/** - * {@link Condition} that checks for any HTTP Service proxy bean. - * - * @author Phillip Webb - * @see ConditionalOnJava - */ -class OnMissingHttpServiceProxyBeanCondition extends SpringBootCondition implements ConfigurationCondition { - - static final String HTTP_SERVICE_GROUP_NAME_ATTRIBUTE = "httpServiceGroupName"; - - @Override - public ConfigurationPhase getConfigurationPhase() { - return ConfigurationPhase.REGISTER_BEAN; - } - - @Override - public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { - ConditionMessage.Builder message = ConditionMessage - .forCondition(ConditionalOnMissingHttpServiceProxyBean.class); - BeanFactory beanFactory = context.getBeanFactory(); - while (beanFactory != null) { - if (beanFactory instanceof ConfigurableListableBeanFactory configurableListableBeanFactory - && hasHttpServiceProxyBeanDefinition(configurableListableBeanFactory)) { - return ConditionOutcome.noMatch(message.foundExactly("HTTP Service proxy bean")); - } - beanFactory = (beanFactory instanceof HierarchicalBeanFactory hierarchicalBeanFactory) - ? hierarchicalBeanFactory.getParentBeanFactory() : null; - } - return ConditionOutcome.match(message.didNotFind("").items("HTTP Service proxy beans")); - } - - private boolean hasHttpServiceProxyBeanDefinition(ConfigurableListableBeanFactory beanFactory) { - for (String beanName : beanFactory.getBeanDefinitionNames()) { - BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); - if (beanDefinition.hasAttribute(HTTP_SERVICE_GROUP_NAME_ATTRIBUTE)) { - return true; - } - } - return false; - } - -} diff --git a/module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/autoconfigure/service/package-info.java b/module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/autoconfigure/service/package-info.java deleted file mode 100644 index 8957dc57003..00000000000 --- a/module/spring-boot-http-client/src/main/java/org/springframework/boot/http/client/autoconfigure/service/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2012-present 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. - */ - -/** - * Common support code for HTTP Service Clients. - */ -@NullMarked -package org.springframework.boot.http.client.autoconfigure.service; - -import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-http-client/src/test/java/org/springframework/boot/http/client/autoconfigure/service/ConditionalOnMissingHttpServiceProxyBeanTests.java b/module/spring-boot-http-client/src/test/java/org/springframework/boot/http/client/autoconfigure/service/ConditionalOnMissingHttpServiceProxyBeanTests.java deleted file mode 100644 index 46b44ac3cca..00000000000 --- a/module/spring-boot-http-client/src/test/java/org/springframework/boot/http/client/autoconfigure/service/ConditionalOnMissingHttpServiceProxyBeanTests.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2012-present 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.boot.http.client.autoconfigure.service; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.util.ReflectionTestUtils; -import org.springframework.web.service.annotation.GetExchange; -import org.springframework.web.service.registry.AbstractHttpServiceRegistrar; -import org.springframework.web.service.registry.ImportHttpServices; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for - * {@link ConditionalOnMissingHttpServiceProxyBean @ConditionalOnMissingHttpServiceProxyBean}. - * - * @author Phillip Webb - */ -class ConditionalOnMissingHttpServiceProxyBeanTests { - - @Test - void attributeNameMatchesSpringFramework() { - assertThat(OnMissingHttpServiceProxyBeanCondition.HTTP_SERVICE_GROUP_NAME_ATTRIBUTE).isEqualTo( - ReflectionTestUtils.getField(AbstractHttpServiceRegistrar.class, "HTTP_SERVICE_GROUP_NAME_ATTRIBUTE")); - } - - @Test - void getOutcomeWhenNoHttpServiceProxyMatches() { - new ApplicationContextRunner().withUserConfiguration(TestConfiguration.class) - .run((context) -> assertThat(context).hasBean("test")); - } - - @Test - void getOutcomeWhenHasHttpServiceProxyDoesNotMatch() { - new ApplicationContextRunner() - .withUserConfiguration(HttpServiceProxyConfiguration.class, TestConfiguration.class) - .run((context) -> assertThat(context).hasSingleBean(TestHttpService.class).doesNotHaveBean("test")); - } - - @Configuration(proxyBeanMethods = false) - @ImportHttpServices(TestHttpService.class) - static class HttpServiceProxyConfiguration { - - } - - @Configuration(proxyBeanMethods = false) - static class TestConfiguration { - - @Bean - @ConditionalOnMissingHttpServiceProxyBean - String test() { - return "test"; - } - - } - - interface TestHttpService { - - @GetExchange("/test") - String test(); - - } - -} diff --git a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/service/HttpServiceClientAutoConfiguration.java b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/service/HttpServiceClientAutoConfiguration.java index 89d51788716..82fbb354421 100644 --- a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/service/HttpServiceClientAutoConfiguration.java +++ b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/service/HttpServiceClientAutoConfiguration.java @@ -16,14 +16,24 @@ package org.springframework.boot.restclient.autoconfigure.service; +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder; +import org.springframework.boot.http.client.ClientHttpRequestFactorySettings; import org.springframework.boot.http.client.autoconfigure.HttpClientAutoConfiguration; +import org.springframework.boot.restclient.RestClientCustomizer; import org.springframework.boot.restclient.autoconfigure.RestClientAutoConfiguration; +import org.springframework.boot.ssl.SslBundles; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Import; +import org.springframework.web.client.ApiVersionFormatter; +import org.springframework.web.client.ApiVersionInserter; import org.springframework.web.client.support.RestClientAdapter; +import org.springframework.web.service.registry.HttpServiceProxyRegistry; import org.springframework.web.service.registry.ImportHttpServices; /** @@ -39,9 +49,37 @@ import org.springframework.web.service.registry.ImportHttpServices; */ @AutoConfiguration(after = { HttpClientAutoConfiguration.class, RestClientAutoConfiguration.class }) @ConditionalOnClass(RestClientAdapter.class) +@ConditionalOnBean(HttpServiceProxyRegistry.class) @Conditional(NotReactiveWebApplicationCondition.class) @EnableConfigurationProperties(HttpClientServiceProperties.class) -@Import({ ImportHttpServiceClientsConfiguration.class, RestClientHttpServiceClientConfiguration.class }) -public final class HttpServiceClientAutoConfiguration { +public final class HttpServiceClientAutoConfiguration implements BeanClassLoaderAware { + + @SuppressWarnings("NullAway.Init") + private ClassLoader beanClassLoader; + + HttpServiceClientAutoConfiguration() { + } + + @Override + public void setBeanClassLoader(ClassLoader classLoader) { + this.beanClassLoader = classLoader; + } + + @Bean + RestClientPropertiesHttpServiceGroupConfigurer restClientPropertiesHttpServiceGroupConfigurer( + ObjectProvider sslBundles, HttpClientServiceProperties serviceProperties, + ObjectProvider> clientFactoryBuilder, + ObjectProvider clientHttpRequestFactorySettings, + ObjectProvider apiVersionInserter, + ObjectProvider apiVersionFormatter) { + return new RestClientPropertiesHttpServiceGroupConfigurer(this.beanClassLoader, sslBundles, serviceProperties, + clientFactoryBuilder, clientHttpRequestFactorySettings, apiVersionInserter, apiVersionFormatter); + } + + @Bean + RestClientCustomizerHttpServiceGroupConfigurer restClientCustomizerHttpServiceGroupConfigurer( + ObjectProvider customizers) { + return new RestClientCustomizerHttpServiceGroupConfigurer(customizers); + } } diff --git a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/service/ImportHttpServiceClientsConfiguration.java b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/service/ImportHttpServiceClientsConfiguration.java deleted file mode 100644 index 87a4526b4a8..00000000000 --- a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/service/ImportHttpServiceClientsConfiguration.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2012-present 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.boot.restclient.autoconfigure.service; - -import org.springframework.beans.factory.BeanFactory; -import org.springframework.boot.autoconfigure.AutoConfigurationPackages; -import org.springframework.boot.http.client.autoconfigure.service.ConditionalOnMissingHttpServiceProxyBean; -import org.springframework.boot.restclient.autoconfigure.service.ImportHttpServiceClientsConfiguration.ImportHttpServiceClients; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.core.type.AnnotationMetadata; -import org.springframework.web.service.registry.AbstractClientHttpServiceRegistrar; -import org.springframework.web.service.registry.HttpServiceClient; - -/** - * {@link Configuration @Configuration} to import {@link ImportHttpServiceClients} when no - * user-defined HTTP service client beans are found. - * - * @author Phillip Webb - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnMissingHttpServiceProxyBean -@Import(ImportHttpServiceClients.class) -class ImportHttpServiceClientsConfiguration { - - /** - * {@link AbstractClientHttpServiceRegistrar} to import - * {@link HttpServiceClient @HttpServiceClient} annotated classes from - * {@link AutoConfigurationPackages}. - */ - static class ImportHttpServiceClients extends AbstractClientHttpServiceRegistrar { - - private final BeanFactory beanFactory; - - ImportHttpServiceClients(BeanFactory beanFactory) { - this.beanFactory = beanFactory; - } - - @Override - protected void registerHttpServices(GroupRegistry registry, AnnotationMetadata importingClassMetadata) { - if (AutoConfigurationPackages.has(this.beanFactory)) { - findAndRegisterHttpServiceClients(registry, AutoConfigurationPackages.get(this.beanFactory)); - } - } - - } - -} diff --git a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/service/RestClientHttpServiceClientConfiguration.java b/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/service/RestClientHttpServiceClientConfiguration.java deleted file mode 100644 index d767f544e05..00000000000 --- a/module/spring-boot-restclient/src/main/java/org/springframework/boot/restclient/autoconfigure/service/RestClientHttpServiceClientConfiguration.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2012-present 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.boot.restclient.autoconfigure.service; - -import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder; -import org.springframework.boot.http.client.ClientHttpRequestFactorySettings; -import org.springframework.boot.restclient.RestClientCustomizer; -import org.springframework.boot.ssl.SslBundles; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.client.ApiVersionFormatter; -import org.springframework.web.client.ApiVersionInserter; -import org.springframework.web.client.RestClient; -import org.springframework.web.client.support.RestClientHttpServiceGroupConfigurer; -import org.springframework.web.service.registry.HttpServiceProxyRegistry; - -/** - * {@link Configuration @Configuration} to register - * {@link RestClientHttpServiceGroupConfigurer} beans to support HTTP service clients - * backed by a {@link RestClient}. - * - * @author Phillip Webb - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnBean(HttpServiceProxyRegistry.class) -class RestClientHttpServiceClientConfiguration implements BeanClassLoaderAware { - - @SuppressWarnings("NullAway.Init") - private ClassLoader beanClassLoader; - - @Override - public void setBeanClassLoader(ClassLoader classLoader) { - this.beanClassLoader = classLoader; - } - - @Bean - RestClientPropertiesHttpServiceGroupConfigurer restClientPropertiesHttpServiceGroupConfigurer( - ObjectProvider sslBundles, HttpClientServiceProperties serviceProperties, - ObjectProvider> clientFactoryBuilder, - ObjectProvider clientHttpRequestFactorySettings, - ObjectProvider apiVersionInserter, - ObjectProvider apiVersionFormatter) { - return new RestClientPropertiesHttpServiceGroupConfigurer(this.beanClassLoader, sslBundles, serviceProperties, - clientFactoryBuilder, clientHttpRequestFactorySettings, apiVersionInserter, apiVersionFormatter); - } - - @Bean - RestClientCustomizerHttpServiceGroupConfigurer restClientCustomizerHttpServiceGroupConfigurer( - ObjectProvider customizers) { - return new RestClientCustomizerHttpServiceGroupConfigurer(customizers); - } - -} diff --git a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/autoconfigure/service/HttpServiceClientAutoConfigurationTests.java b/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/autoconfigure/service/HttpServiceClientAutoConfigurationTests.java index 924cc70822e..86d4411d591 100644 --- a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/autoconfigure/service/HttpServiceClientAutoConfigurationTests.java +++ b/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/autoconfigure/service/HttpServiceClientAutoConfigurationTests.java @@ -28,7 +28,6 @@ import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.springframework.aop.Advisor; -import org.springframework.boot.autoconfigure.AutoConfigurationPackage; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder; import org.springframework.boot.http.client.ClientHttpRequestFactorySettings; @@ -36,7 +35,6 @@ import org.springframework.boot.http.client.HttpRedirects; import org.springframework.boot.http.client.autoconfigure.HttpClientAutoConfiguration; import org.springframework.boot.restclient.RestClientCustomizer; import org.springframework.boot.restclient.autoconfigure.RestClientAutoConfiguration; -import org.springframework.boot.restclient.autoconfigure.service.scan.TestHttpServiceClient; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -195,18 +193,6 @@ class HttpServiceClientAutoConfigurationTests { .run((context) -> assertThat(context).doesNotHaveBean(HttpServiceProxyRegistry.class)); } - @Test - void registerHttpServiceAnnotatedInterfacesInPackages() { - this.contextRunner.withUserConfiguration(ScanConfiguration.class) - .run((context) -> assertThat(context).hasSingleBean(TestHttpServiceClient.class)); - } - - @Test - void whenHasImportAnnotationDoesNotRegisterHttpServiceAnnotatedInterfacesInPackages() { - this.contextRunner.withUserConfiguration(ScanConfiguration.class, HttpClientConfiguration.class) - .run((context) -> assertThat(context).doesNotHaveBean(TestHttpServiceClient.class)); - } - private HttpClient getJdkHttpClient(Object proxy) { return (HttpClient) Extractors.byName("clientRequestFactory.httpClient").apply(getRestClient(proxy)); } @@ -289,12 +275,6 @@ class HttpServiceClientAutoConfigurationTests { } - @Configuration(proxyBeanMethods = false) - @AutoConfigurationPackage(basePackageClasses = TestHttpServiceClient.class) - static class ScanConfiguration { - - } - interface TestClientOne { @GetExchange("/hello") diff --git a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/autoconfigure/service/scan/TestHttpServiceClient.java b/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/autoconfigure/service/scan/TestHttpServiceClient.java deleted file mode 100644 index 48aae740648..00000000000 --- a/module/spring-boot-restclient/src/test/java/org/springframework/boot/restclient/autoconfigure/service/scan/TestHttpServiceClient.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-present 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.boot.restclient.autoconfigure.service.scan; - -import org.springframework.web.service.annotation.GetExchange; -import org.springframework.web.service.registry.HttpServiceClient; - -/** - * Test HTTP service used with scanning. - * - * @author Phillip Webb - */ -@HttpServiceClient("test") -public interface TestHttpServiceClient { - - @GetExchange("/hello") - String hello(); - -} diff --git a/module/spring-boot-webclient/src/main/java/org/springframework/boot/webclient/autoconfigure/service/ImportHttpServiceClientsConfiguration.java b/module/spring-boot-webclient/src/main/java/org/springframework/boot/webclient/autoconfigure/service/ImportHttpServiceClientsConfiguration.java deleted file mode 100644 index 72cffada8d3..00000000000 --- a/module/spring-boot-webclient/src/main/java/org/springframework/boot/webclient/autoconfigure/service/ImportHttpServiceClientsConfiguration.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2012-present 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.boot.webclient.autoconfigure.service; - -import org.springframework.beans.factory.BeanFactory; -import org.springframework.boot.autoconfigure.AutoConfigurationPackages; -import org.springframework.boot.http.client.autoconfigure.service.ConditionalOnMissingHttpServiceProxyBean; -import org.springframework.boot.webclient.autoconfigure.service.ImportHttpServiceClientsConfiguration.ImportHttpServiceClients; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.core.type.AnnotationMetadata; -import org.springframework.web.service.registry.AbstractClientHttpServiceRegistrar; -import org.springframework.web.service.registry.HttpServiceClient; - -/** - * {@link Configuration @Configuration} to import {@link ImportHttpServiceClients} when no - * user-defined HTTP service client beans are found. - * - * @author Phillip Webb - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnMissingHttpServiceProxyBean -@Import(ImportHttpServiceClients.class) -class ImportHttpServiceClientsConfiguration { - - /** - * {@link AbstractClientHttpServiceRegistrar} to import - * {@link HttpServiceClient @HttpServiceClient} annotated classes from - * {@link AutoConfigurationPackages}. - */ - static class ImportHttpServiceClients extends AbstractClientHttpServiceRegistrar { - - private final BeanFactory beanFactory; - - ImportHttpServiceClients(BeanFactory beanFactory) { - this.beanFactory = beanFactory; - } - - @Override - protected void registerHttpServices(GroupRegistry registry, AnnotationMetadata importingClassMetadata) { - if (AutoConfigurationPackages.has(this.beanFactory)) { - findAndRegisterHttpServiceClients(registry, AutoConfigurationPackages.get(this.beanFactory)); - } - } - - } - -} diff --git a/module/spring-boot-webclient/src/main/java/org/springframework/boot/webclient/autoconfigure/service/ReactiveHttpServiceClientAutoConfiguration.java b/module/spring-boot-webclient/src/main/java/org/springframework/boot/webclient/autoconfigure/service/ReactiveHttpServiceClientAutoConfiguration.java index 1acb56a85f7..56001641129 100644 --- a/module/spring-boot-webclient/src/main/java/org/springframework/boot/webclient/autoconfigure/service/ReactiveHttpServiceClientAutoConfiguration.java +++ b/module/spring-boot-webclient/src/main/java/org/springframework/boot/webclient/autoconfigure/service/ReactiveHttpServiceClientAutoConfiguration.java @@ -16,13 +16,23 @@ package org.springframework.boot.webclient.autoconfigure.service; +import org.springframework.beans.factory.BeanClassLoaderAware; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.http.client.autoconfigure.reactive.ClientHttpConnectorAutoConfiguration; +import org.springframework.boot.http.client.reactive.ClientHttpConnectorBuilder; +import org.springframework.boot.http.client.reactive.ClientHttpConnectorSettings; +import org.springframework.boot.ssl.SslBundles; +import org.springframework.boot.webclient.WebClientCustomizer; import org.springframework.boot.webclient.autoconfigure.WebClientAutoConfiguration; -import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.ApiVersionFormatter; +import org.springframework.web.client.ApiVersionInserter; import org.springframework.web.reactive.function.client.support.WebClientAdapter; +import org.springframework.web.service.registry.HttpServiceProxyRegistry; import org.springframework.web.service.registry.ImportHttpServices; /** @@ -38,8 +48,36 @@ import org.springframework.web.service.registry.ImportHttpServices; */ @AutoConfiguration(after = { ClientHttpConnectorAutoConfiguration.class, WebClientAutoConfiguration.class }) @ConditionalOnClass(WebClientAdapter.class) +@ConditionalOnBean(HttpServiceProxyRegistry.class) @EnableConfigurationProperties(ReactiveHttpClientServiceProperties.class) -@Import({ ImportHttpServiceClientsConfiguration.class, WebClientHttpServiceClientConfiguration.class }) -public final class ReactiveHttpServiceClientAutoConfiguration { +public final class ReactiveHttpServiceClientAutoConfiguration implements BeanClassLoaderAware { + + @SuppressWarnings("NullAway.Init") + private ClassLoader beanClassLoader; + + ReactiveHttpServiceClientAutoConfiguration() { + } + + @Override + public void setBeanClassLoader(ClassLoader classLoader) { + this.beanClassLoader = classLoader; + } + + @Bean + WebClientPropertiesHttpServiceGroupConfigurer webClientPropertiesHttpServiceGroupConfigurer( + ObjectProvider sslBundles, ReactiveHttpClientServiceProperties serviceProperties, + ObjectProvider> clientConnectorBuilder, + ObjectProvider clientConnectorSettings, + ObjectProvider apiVersionInserter, + ObjectProvider apiVersionFormatter) { + return new WebClientPropertiesHttpServiceGroupConfigurer(this.beanClassLoader, sslBundles, serviceProperties, + clientConnectorBuilder, clientConnectorSettings, apiVersionInserter, apiVersionFormatter); + } + + @Bean + WebClientCustomizerHttpServiceGroupConfigurer webClientCustomizerHttpServiceGroupConfigurer( + ObjectProvider customizers) { + return new WebClientCustomizerHttpServiceGroupConfigurer(customizers); + } } diff --git a/module/spring-boot-webclient/src/main/java/org/springframework/boot/webclient/autoconfigure/service/WebClientHttpServiceClientConfiguration.java b/module/spring-boot-webclient/src/main/java/org/springframework/boot/webclient/autoconfigure/service/WebClientHttpServiceClientConfiguration.java deleted file mode 100644 index 1b26a98d534..00000000000 --- a/module/spring-boot-webclient/src/main/java/org/springframework/boot/webclient/autoconfigure/service/WebClientHttpServiceClientConfiguration.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2012-present 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.boot.webclient.autoconfigure.service; - -import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.http.client.reactive.ClientHttpConnectorBuilder; -import org.springframework.boot.http.client.reactive.ClientHttpConnectorSettings; -import org.springframework.boot.ssl.SslBundles; -import org.springframework.boot.webclient.WebClientCustomizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.client.ApiVersionFormatter; -import org.springframework.web.client.ApiVersionInserter; -import org.springframework.web.reactive.function.client.WebClient; -import org.springframework.web.reactive.function.client.support.WebClientHttpServiceGroupConfigurer; -import org.springframework.web.service.registry.HttpServiceProxyRegistry; - -/** - * {@link Configuration @Configuration} to register - * {@link WebClientHttpServiceGroupConfigurer} beans to support HTTP service clients - * backed by a {@link WebClient}. - * - * @author Phillip Webb - */ -@Configuration(proxyBeanMethods = false) -@ConditionalOnBean(HttpServiceProxyRegistry.class) -final class WebClientHttpServiceClientConfiguration implements BeanClassLoaderAware { - - @SuppressWarnings("NullAway.Init") - private ClassLoader beanClassLoader; - - @Override - public void setBeanClassLoader(ClassLoader classLoader) { - this.beanClassLoader = classLoader; - } - - @Bean - WebClientPropertiesHttpServiceGroupConfigurer webClientPropertiesHttpServiceGroupConfigurer( - ObjectProvider sslBundles, ReactiveHttpClientServiceProperties serviceProperties, - ObjectProvider> clientConnectorBuilder, - ObjectProvider clientConnectorSettings, - ObjectProvider apiVersionInserter, - ObjectProvider apiVersionFormatter) { - return new WebClientPropertiesHttpServiceGroupConfigurer(this.beanClassLoader, sslBundles, serviceProperties, - clientConnectorBuilder, clientConnectorSettings, apiVersionInserter, apiVersionFormatter); - } - - @Bean - WebClientCustomizerHttpServiceGroupConfigurer webClientCustomizerHttpServiceGroupConfigurer( - ObjectProvider customizers) { - return new WebClientCustomizerHttpServiceGroupConfigurer(customizers); - } - -} diff --git a/module/spring-boot-webclient/src/test/java/org/springframework/boot/webclient/autoconfigure/service/ReactiveHttpServiceClientAutoConfigurationTests.java b/module/spring-boot-webclient/src/test/java/org/springframework/boot/webclient/autoconfigure/service/ReactiveHttpServiceClientAutoConfigurationTests.java index 0097349d21c..93a9dcc4f36 100644 --- a/module/spring-boot-webclient/src/test/java/org/springframework/boot/webclient/autoconfigure/service/ReactiveHttpServiceClientAutoConfigurationTests.java +++ b/module/spring-boot-webclient/src/test/java/org/springframework/boot/webclient/autoconfigure/service/ReactiveHttpServiceClientAutoConfigurationTests.java @@ -29,7 +29,6 @@ import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.springframework.aop.Advisor; -import org.springframework.boot.autoconfigure.AutoConfigurationPackage; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.http.client.HttpRedirects; import org.springframework.boot.http.client.autoconfigure.reactive.ClientHttpConnectorAutoConfiguration; @@ -38,7 +37,6 @@ import org.springframework.boot.http.client.reactive.ClientHttpConnectorSettings import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; import org.springframework.boot.webclient.WebClientCustomizer; import org.springframework.boot.webclient.autoconfigure.WebClientAutoConfiguration; -import org.springframework.boot.webclient.autoconfigure.service.scan.TestHttpServiceClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; @@ -182,18 +180,6 @@ class ReactiveHttpServiceClientAutoConfigurationTests { .run((context) -> assertThat(context).doesNotHaveBean(HttpServiceProxyRegistry.class)); } - @Test - void registerHttpServiceAnnotatedInterfacesInPackages() { - this.contextRunner.withUserConfiguration(ScanConfiguration.class) - .run((context) -> assertThat(context).hasSingleBean(TestHttpServiceClient.class)); - } - - @Test - void whenHasImportAnnotationDoesNotRegisterHttpServiceAnnotatedInterfacesInPackages() { - this.contextRunner.withUserConfiguration(ScanConfiguration.class, HttpClientConfiguration.class) - .run((context) -> assertThat(context).doesNotHaveBean(TestHttpServiceClient.class)); - } - private HttpClient getJdkHttpClient(Object proxy) { return (HttpClient) Extractors.byName("builder.connector.httpClient").apply(getWebClient(proxy)); } @@ -263,12 +249,6 @@ class ReactiveHttpServiceClientAutoConfigurationTests { } - @Configuration(proxyBeanMethods = false) - @AutoConfigurationPackage(basePackageClasses = TestHttpServiceClient.class) - static class ScanConfiguration { - - } - interface TestClientOne { @GetExchange("/hello") diff --git a/module/spring-boot-webclient/src/test/java/org/springframework/boot/webclient/autoconfigure/service/scan/TestHttpServiceClient.java b/module/spring-boot-webclient/src/test/java/org/springframework/boot/webclient/autoconfigure/service/scan/TestHttpServiceClient.java deleted file mode 100644 index 3789366b7b4..00000000000 --- a/module/spring-boot-webclient/src/test/java/org/springframework/boot/webclient/autoconfigure/service/scan/TestHttpServiceClient.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-present 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.boot.webclient.autoconfigure.service.scan; - -import org.springframework.web.service.annotation.GetExchange; -import org.springframework.web.service.registry.HttpServiceClient; - -/** - * Test HTTP service used with scanning. - * - * @author Phillip Webb - */ -@HttpServiceClient("test") -public interface TestHttpServiceClient { - - @GetExchange("/hello") - String hello(); - -}