Skip to content

Commit 6a26db8

Browse files
committed
Refine RouterFunctionMapping ordering consistency
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
1 parent ccf6887 commit 6a26db8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@
121121
*
122122
* <p>This class registers the following {@link HandlerMapping HandlerMappings}:</p>
123123
* <ul>
124+
* <li>{@link RouterFunctionMapping}
125+
* ordered at -1 to map {@linkplain org.springframework.web.servlet.function.RouterFunction router functions}.
124126
* <li>{@link RequestMappingHandlerMapping}
125127
* ordered at 0 for mapping requests to annotated controller methods.
126128
* <li>{@link HandlerMapping}
127129
* ordered at 1 to map URL paths directly to view names.
128130
* <li>{@link BeanNameUrlHandlerMapping}
129131
* ordered at 2 to map URL paths to controller bean names.
130-
* <li>{@link RouterFunctionMapping}
131-
* ordered at 3 to map {@linkplain org.springframework.web.servlet.function.RouterFunction router functions}.
132132
* <li>{@link HandlerMapping}
133133
* ordered at {@code Integer.MAX_VALUE-1} to serve static resource requests.
134134
* <li>{@link HandlerMapping}
@@ -535,7 +535,7 @@ public BeanNameUrlHandlerMapping beanNameHandlerMapping(
535535
}
536536

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

554554
RouterFunctionMapping mapping = new RouterFunctionMapping();
555-
mapping.setOrder(3);
555+
mapping.setOrder(-1); // go before RequestMappingHandlerMapping
556556
mapping.setInterceptors(getInterceptors(conversionService, resourceUrlProvider));
557557
mapping.setCorsConfigurations(getCorsConfigurations());
558558
mapping.setMessageConverters(getMessageConverters());

0 commit comments

Comments
 (0)