diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration.java index ba059641d0..e1a482de06 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.web.reactive; import java.util.Collections; import java.util.Map; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureOrder; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -60,9 +61,10 @@ public class HttpHandlerAutoConfiguration { } @Bean - public HttpHandler httpHandler(WebFluxProperties properties) { + public HttpHandler httpHandler(ObjectProvider propsProvider) { HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(this.applicationContext).build(); - if (StringUtils.hasText(properties.getBasePath())) { + WebFluxProperties properties = propsProvider.getIfAvailable(); + if (properties != null && StringUtils.hasText(properties.getBasePath())) { Map handlersMap = Collections.singletonMap(properties.getBasePath(), httpHandler); return new ContextPathCompositeHandler(handlersMap); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java index 81845b4405..4c44adc556 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java @@ -25,8 +25,10 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.server.reactive.ContextPathCompositeHandler; import org.springframework.http.server.reactive.HttpHandler; +import org.springframework.web.reactive.DispatcherHandler; import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.ServerResponse; +import org.springframework.web.server.WebHandler; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.web.reactive.function.server.RequestPredicates.GET; @@ -58,6 +60,12 @@ class HttpHandlerAutoConfigurationTests { .run((context) -> assertThat(context).hasSingleBean(HttpHandler.class)); } + @Test + void shouldConfigureHttpHandlerWithoutWebFluxAutoConfiguration() { + this.contextRunner.withUserConfiguration(CustomWebHandler.class) + .run((context) -> assertThat(context).hasSingleBean(HttpHandler.class)); + } + @Test void shouldConfigureBasePathCompositeHandler() { this.contextRunner.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class)) @@ -85,4 +93,14 @@ class HttpHandlerAutoConfigurationTests { } + @Configuration(proxyBeanMethods = false) + static class CustomWebHandler { + + @Bean + WebHandler webHandler() { + return new DispatcherHandler(); + } + + } + }