Skip to content

Commit

Permalink
Allow user's WebFluxConfigurers to be ordered after auto-config's
Browse files Browse the repository at this point in the history
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 spring-projectsgh-25302
  • Loading branch information
wilkinsona committed Feb 24, 2021
1 parent 76e42ff commit 2a2daae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
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;
Expand Down Expand Up @@ -133,6 +134,7 @@ public RouterFunctionMapping welcomePageRouterFunctionMapping(ApplicationContext
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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;
Expand Down Expand Up @@ -66,6 +67,7 @@
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;
Expand Down Expand Up @@ -544,6 +546,17 @@ void customLocaleContextResolverWithDifferentNameDoesNotReplaceAutoConfiguredLoc
});
}

@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<PathPattern, Object> getHandlerMap(ApplicationContext context) {
HandlerMapping mapping = context.getBean("resourceHandlerMapping", HandlerMapping.class);
if (mapping instanceof SimpleUrlHandlerMapping) {
Expand Down Expand Up @@ -787,4 +800,14 @@ public void setLocaleContext(ServerWebExchange exchange, LocaleContext localeCon

}

@Order(-100)
static class HighPrecedenceConfigurer implements WebFluxConfigurer {

}

@Order(100)
static class LowPrecedenceConfigurer implements WebFluxConfigurer {

}

}

0 comments on commit 2a2daae

Please sign in to comment.