Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine RouterFunctionMapping ordering consistency #30278

Closed
sdeleuze opened this issue Apr 4, 2023 · 1 comment
Closed

Refine RouterFunctionMapping ordering consistency #30278

sdeleuze opened this issue Apr 4, 2023 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Apr 4, 2023

Related to spring-projects/spring-boot#34846, it would be great to refine if possible the relative ordering between RouterFunctionMapping and other mapping to have a better consistency between Spring WebFlux (where RouterFunctionMapping is before RequestMappingHandlerMapping) and Spring MVC (where this is the other way around).

@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Apr 4, 2023
@sdeleuze sdeleuze added this to the 6.1.0-M1 milestone Apr 4, 2023
@sdeleuze sdeleuze self-assigned this Apr 6, 2023
@sdeleuze
Copy link
Contributor Author

We are going to change, as of Spring Framework 6.1, the order of RouterFunctionMapping defined in WebMvcConfigurationSupport from 3 to -1 in order to achieve better consistency and reduce the surprise factor. That way, functional routes will always be before annotation-based ones.

It also makes sense from a user perspective since functional routes are kind of lower level than annotation-based ones, and the overhead will be minimal for pure annotation-based use cases because if there are no RouterFunction in the application context, then RouterFunctionMapping::routerFunction is null, and the mapping does not allocate anything (no Optional<HandlerFunction<T>> instance have to be created).

mdeinum pushed a commit to mdeinum/spring-framework that referenced this issue Jun 29, 2023
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 spring-projectsgh-30278
bclozel added a commit to spring-projects/spring-boot that referenced this issue Oct 16, 2023
Prior to this commit, the GraphQL WebSocket HandlerMapping bean would be
ordered at position "2", before the RouterFunction variant defined by
Spring Framework at position "3".

Since then, the Spring Framework team changed the default order value
for this one at "-1", see spring-projects/spring-framework#30278.
This prevents the WebSocket upgrade, as the request is handled by the
RouterFunction instead of the WebSocket handler.

This commit updates the handlermapping order and introduces a test to
prevent issues in the future.

Fixes gh-37892
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant