Skip to content

Commit 2a2daae

Browse files
committed
Allow user's WebFluxConfigurers to be ordered after auto-config's
Previously, WebFluxAutoConfiguration's WebFluxConfigurer was unordered. This mean that it had lowest precedence so it was not possible for a user to provide their own configurer that was guaranteed to run after the auto-configuration's configurer. This commit updates the auto-configuration to order its configurer at 0. Any unordered user-defined configurer will now run after the auto-configuration's configurer. Closes gh-25302
1 parent 76e42ff commit 2a2daae

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.springframework.context.annotation.Configuration;
5050
import org.springframework.context.annotation.Import;
5151
import org.springframework.core.Ordered;
52+
import org.springframework.core.annotation.Order;
5253
import org.springframework.format.FormatterRegistry;
5354
import org.springframework.format.support.FormattingConversionService;
5455
import org.springframework.http.codec.ServerCodecConfigurer;
@@ -133,6 +134,7 @@ public RouterFunctionMapping welcomePageRouterFunctionMapping(ApplicationContext
133134
@EnableConfigurationProperties({ org.springframework.boot.autoconfigure.web.ResourceProperties.class,
134135
WebProperties.class, WebFluxProperties.class })
135136
@Import({ EnableWebFluxConfiguration.class })
137+
@Order(0)
136138
public static class WebFluxConfig implements WebFluxConfigurer {
137139

138140
private static final Log logger = LogFactory.getLog(WebFluxConfig.class);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.springframework.boot.autoconfigure.AutoConfigurations;
4040
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
4141
import org.springframework.boot.autoconfigure.validation.ValidatorAdapter;
42+
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration.WebFluxConfig;
4243
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
4344
import org.springframework.boot.web.codec.CodecCustomizer;
4445
import org.springframework.boot.web.reactive.filter.OrderedHiddenHttpMethodFilter;
@@ -66,6 +67,7 @@
6667
import org.springframework.web.filter.reactive.HiddenHttpMethodFilter;
6768
import org.springframework.web.reactive.HandlerMapping;
6869
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
70+
import org.springframework.web.reactive.config.DelegatingWebFluxConfiguration;
6971
import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
7072
import org.springframework.web.reactive.config.WebFluxConfigurer;
7173
import org.springframework.web.reactive.function.server.support.RouterFunctionMapping;
@@ -544,6 +546,17 @@ void customLocaleContextResolverWithDifferentNameDoesNotReplaceAutoConfiguredLoc
544546
});
545547
}
546548

549+
@Test
550+
@SuppressWarnings("rawtypes")
551+
void userConfigurersCanBeOrderedBeforeOrAfterTheAutoConfiguredConfigurer() {
552+
this.contextRunner.withBean(HighPrecedenceConfigurer.class, HighPrecedenceConfigurer::new)
553+
.withBean(LowPrecedenceConfigurer.class, LowPrecedenceConfigurer::new)
554+
.run((context) -> assertThat(context.getBean(DelegatingWebFluxConfiguration.class))
555+
.extracting("configurers.delegates").asList()
556+
.extracting((configurer) -> (Class) configurer.getClass()).containsExactly(
557+
HighPrecedenceConfigurer.class, WebFluxConfig.class, LowPrecedenceConfigurer.class));
558+
}
559+
547560
private Map<PathPattern, Object> getHandlerMap(ApplicationContext context) {
548561
HandlerMapping mapping = context.getBean("resourceHandlerMapping", HandlerMapping.class);
549562
if (mapping instanceof SimpleUrlHandlerMapping) {
@@ -787,4 +800,14 @@ public void setLocaleContext(ServerWebExchange exchange, LocaleContext localeCon
787800

788801
}
789802

803+
@Order(-100)
804+
static class HighPrecedenceConfigurer implements WebFluxConfigurer {
805+
806+
}
807+
808+
@Order(100)
809+
static class LowPrecedenceConfigurer implements WebFluxConfigurer {
810+
811+
}
812+
790813
}

0 commit comments

Comments
 (0)