diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java index 41349b5848..9b201e8b95 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java @@ -49,6 +49,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; import org.springframework.format.FormatterRegistry; import org.springframework.format.support.FormattingConversionService; import org.springframework.http.codec.ServerCodecConfigurer; @@ -133,6 +134,7 @@ public class WebFluxAutoConfiguration { @EnableConfigurationProperties({ org.springframework.boot.autoconfigure.web.ResourceProperties.class, WebProperties.class, WebFluxProperties.class }) @Import({ EnableWebFluxConfiguration.class }) + @Order(0) public static class WebFluxConfig implements WebFluxConfigurer { private static final Log logger = LogFactory.getLog(WebFluxConfig.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java index c105b0f328..b04e9eefd6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java @@ -39,6 +39,7 @@ import org.junit.jupiter.params.provider.ValueSource; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration; import org.springframework.boot.autoconfigure.validation.ValidatorAdapter; +import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration.WebFluxConfig; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; import org.springframework.boot.web.codec.CodecCustomizer; import org.springframework.boot.web.reactive.filter.OrderedHiddenHttpMethodFilter; @@ -66,6 +67,7 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import org.springframework.web.filter.reactive.HiddenHttpMethodFilter; import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.accept.RequestedContentTypeResolver; +import org.springframework.web.reactive.config.DelegatingWebFluxConfiguration; import org.springframework.web.reactive.config.WebFluxConfigurationSupport; import org.springframework.web.reactive.config.WebFluxConfigurer; import org.springframework.web.reactive.function.server.support.RouterFunctionMapping; @@ -544,6 +546,17 @@ class WebFluxAutoConfigurationTests { }); } + @Test + @SuppressWarnings("rawtypes") + void userConfigurersCanBeOrderedBeforeOrAfterTheAutoConfiguredConfigurer() { + this.contextRunner.withBean(HighPrecedenceConfigurer.class, HighPrecedenceConfigurer::new) + .withBean(LowPrecedenceConfigurer.class, LowPrecedenceConfigurer::new) + .run((context) -> assertThat(context.getBean(DelegatingWebFluxConfiguration.class)) + .extracting("configurers.delegates").asList() + .extracting((configurer) -> (Class) configurer.getClass()).containsExactly( + HighPrecedenceConfigurer.class, WebFluxConfig.class, LowPrecedenceConfigurer.class)); + } + private Map getHandlerMap(ApplicationContext context) { HandlerMapping mapping = context.getBean("resourceHandlerMapping", HandlerMapping.class); if (mapping instanceof SimpleUrlHandlerMapping) { @@ -787,4 +800,14 @@ class WebFluxAutoConfigurationTests { } + @Order(-100) + static class HighPrecedenceConfigurer implements WebFluxConfigurer { + + } + + @Order(100) + static class LowPrecedenceConfigurer implements WebFluxConfigurer { + + } + }