Skip to content

Commit

Permalink
Refine RouterFunctionMapping ordering consistency
Browse files Browse the repository at this point in the history
This commit changes the order of RouterFunctionMapping defined
in WebMvcConfigurationSupport from 3 to -1 in order to achieve
better consistency between WebMVC and WebFlux. It also reduces
the surprise factor. That way, functional routes are always
before annotation-based ones.

Closes gh-30278
  • Loading branch information
sdeleuze committed Jun 13, 2023
1 parent ccf6887 commit 6a26db8
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@
*
* <p>This class registers the following {@link HandlerMapping HandlerMappings}:</p>
* <ul>
* <li>{@link RouterFunctionMapping}
* ordered at -1 to map {@linkplain org.springframework.web.servlet.function.RouterFunction router functions}.
* <li>{@link RequestMappingHandlerMapping}
* ordered at 0 for mapping requests to annotated controller methods.
* <li>{@link HandlerMapping}
* ordered at 1 to map URL paths directly to view names.
* <li>{@link BeanNameUrlHandlerMapping}
* ordered at 2 to map URL paths to controller bean names.
* <li>{@link RouterFunctionMapping}
* ordered at 3 to map {@linkplain org.springframework.web.servlet.function.RouterFunction router functions}.
* <li>{@link HandlerMapping}
* ordered at {@code Integer.MAX_VALUE-1} to serve static resource requests.
* <li>{@link HandlerMapping}
Expand Down Expand Up @@ -535,7 +535,7 @@ public BeanNameUrlHandlerMapping beanNameHandlerMapping(
}

/**
* Return a {@link RouterFunctionMapping} ordered at 3 to map
* Return a {@link RouterFunctionMapping} ordered at -1 to map
* {@linkplain org.springframework.web.servlet.function.RouterFunction router functions}.
* Consider overriding one of these other more fine-grained methods:
* <ul>
Expand All @@ -552,7 +552,7 @@ public RouterFunctionMapping routerFunctionMapping(
@Qualifier("mvcResourceUrlProvider") ResourceUrlProvider resourceUrlProvider) {

RouterFunctionMapping mapping = new RouterFunctionMapping();
mapping.setOrder(3);
mapping.setOrder(-1); // go before RequestMappingHandlerMapping
mapping.setInterceptors(getInterceptors(conversionService, resourceUrlProvider));
mapping.setCorsConfigurations(getCorsConfigurations());
mapping.setMessageConverters(getMessageConverters());
Expand Down

0 comments on commit 6a26db8

Please sign in to comment.