diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/ClientHttpRequestFactories.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/ClientHttpRequestFactories.java
index 168021cea3..af790cb19b 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/ClientHttpRequestFactories.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/ClientHttpRequestFactories.java
@@ -73,10 +73,12 @@ public final class ClientHttpRequestFactories {
private
T getProperty(Function accessor, Function extractor,
Predicate predicate) {
for (AbstractHttpRequestFactoryProperties properties : this.orderedProperties) {
- P value = accessor.apply(properties);
- T extracted = (value != null) ? extractor.apply(value) : null;
- if (predicate.test(extracted)) {
- return extracted;
+ if (properties != null) {
+ P value = accessor.apply(properties);
+ T extracted = (value != null) ? extractor.apply(value) : null;
+ if (predicate.test(extracted)) {
+ return extracted;
+ }
}
}
return null;
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/reactive/ClientHttpConnectors.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/reactive/ClientHttpConnectors.java
index ff962c30ee..9ad9400a95 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/reactive/ClientHttpConnectors.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/reactive/ClientHttpConnectors.java
@@ -73,10 +73,12 @@ public final class ClientHttpConnectors {
private T getProperty(Function accessor, Function extractor,
Predicate predicate) {
for (AbstractClientHttpConnectorProperties properties : this.orderedProperties) {
- P value = accessor.apply(properties);
- T extracted = (value != null) ? extractor.apply(value) : null;
- if (predicate.test(extracted)) {
- return extracted;
+ if (properties != null) {
+ P value = accessor.apply(properties);
+ T extracted = (value != null) ? extractor.apply(value) : null;
+ if (predicate.test(extracted)) {
+ return extracted;
+ }
}
}
return null;
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/service/HttpServiceClientAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/service/HttpServiceClientAutoConfiguration.java
index 431e48f5eb..6ca0b74e8e 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/service/HttpServiceClientAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/service/HttpServiceClientAutoConfiguration.java
@@ -30,6 +30,7 @@ import org.springframework.boot.http.client.ClientHttpRequestFactorySettings;
import org.springframework.boot.ssl.SslBundles;
import org.springframework.boot.web.client.RestClientCustomizer;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
import org.springframework.web.client.support.RestClientAdapter;
import org.springframework.web.service.registry.HttpServiceProxyRegistry;
import org.springframework.web.service.registry.ImportHttpServices;
@@ -48,6 +49,7 @@ 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)
public class HttpServiceClientAutoConfiguration implements BeanClassLoaderAware {
@@ -63,12 +65,13 @@ public class HttpServiceClientAutoConfiguration implements BeanClassLoaderAware
@Bean
RestClientPropertiesHttpServiceGroupConfigurer restClientPropertiesHttpServiceGroupConfigurer(
- ObjectProvider sslBundles, HttpClientProperties httpClientProperties,
+ ObjectProvider sslBundles, ObjectProvider httpClientProperties,
HttpClientServiceProperties serviceProperties,
ObjectProvider> clientFactoryBuilder,
ObjectProvider clientHttpRequestFactorySettings) {
return new RestClientPropertiesHttpServiceGroupConfigurer(this.beanClassLoader, sslBundles,
- httpClientProperties, serviceProperties, clientFactoryBuilder, clientHttpRequestFactorySettings);
+ httpClientProperties.getIfAvailable(), serviceProperties, clientFactoryBuilder,
+ clientHttpRequestFactorySettings);
}
@Bean
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/service/NotReactiveWebApplicationCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/service/NotReactiveWebApplicationCondition.java
new file mode 100644
index 0000000000..12be9ee534
--- /dev/null
+++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/client/service/NotReactiveWebApplicationCondition.java
@@ -0,0 +1,40 @@
+/*
+ * 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.boot.autoconfigure.http.client.service;
+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
+import org.springframework.boot.autoconfigure.condition.NoneNestedConditions;
+import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
+
+/**
+ * {@link SpringBootCondition} that applies only when running in a non-reactive web
+ * application.
+ *
+ * @author Phillip Webb
+ */
+class NotReactiveWebApplicationCondition extends NoneNestedConditions {
+
+ NotReactiveWebApplicationCondition() {
+ super(ConfigurationPhase.PARSE_CONFIGURATION);
+ }
+
+ @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
+ private static final class ReactiveWebApplication {
+
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/client/reactive/service/ReactiveHttpServiceClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/client/reactive/service/ReactiveHttpServiceClientAutoConfigurationTests.java
index 155eefaa51..c2cc722eaa 100644
--- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/client/reactive/service/ReactiveHttpServiceClientAutoConfigurationTests.java
+++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/client/reactive/service/ReactiveHttpServiceClientAutoConfigurationTests.java
@@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.Advisor;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.http.client.reactive.ClientHttpConnectorAutoConfiguration;
+import org.springframework.boot.autoconfigure.http.client.service.HttpServiceClientAutoConfiguration;
import org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration;
import org.springframework.boot.http.client.HttpRedirects;
import org.springframework.boot.http.client.reactive.ClientHttpConnectorBuilder;
@@ -58,8 +59,9 @@ import static org.assertj.core.api.Assertions.assertThat;
class ReactiveHttpServiceClientAutoConfigurationTests {
private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner()
- .withConfiguration(AutoConfigurations.of(ReactiveHttpServiceClientAutoConfiguration.class,
- ClientHttpConnectorAutoConfiguration.class, WebClientAutoConfiguration.class));
+ .withConfiguration(AutoConfigurations.of(HttpServiceClientAutoConfiguration.class,
+ ReactiveHttpServiceClientAutoConfiguration.class, ClientHttpConnectorAutoConfiguration.class,
+ WebClientAutoConfiguration.class));
@Test
void configuresClientFromProperties() {