Skip to content

Document Welcome Page support ordering #34846

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

Closed
sdeleuze opened this issue Apr 4, 2023 · 6 comments
Closed

Document Welcome Page support ordering #34846

sdeleuze opened this issue Apr 4, 2023 · 6 comments
Assignees
Labels
type: documentation A documentation update
Milestone

Comments

@sdeleuze
Copy link
Contributor

sdeleuze commented Apr 4, 2023

When using WebMvc.fn, the order of the registered mapping is:

  • RequestMappingHandlerMapping (order 0, set by Framework)
  • WelcomePageHandlerMapping (order 2, set by Boot)
  • RouterFunctionMapping (order 3, set by Framework)

Which leads to the surprising behavior that a RouterFunction define a user provided mapping on / to render a index template will be shadowed by WelcomePageHandlerMapping serving this template. In my case, that half broke the rendering by skipping the model attributes that were set in the handler.

After a discussion with the Spring Framework team, we are going to try to improve the consistency between WebFlux (which has RouterFunctionMapping before RequestMappingHandlerMapping ) and WebMvc (where this is the opposite) if possible (see spring-projects/spring-framework#30278) but we can't change that in a 5.3 or 6.0 patch release.

But I think I would be great if possible to fix Spring Boot 3.0 and potentially 2.7 to have WelcomePageHandlerMapping after RouterFunctionMapping.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 4, 2023
@snicoll snicoll added the for: team-attention An issue we'd like other members of the team to review label Apr 4, 2023
@wilkinsona
Copy link
Member

I'm not sure that we can change this in a maintenance release for the same reasons that you don't want to re-order RequestMappingHandlerMapping and RouterFunctionMapping in a Framework maintenance release. With spring-projects/spring-framework#30278 scheduled for Framework 6.1, I think we should schedule this for Boot 3.2.

I wonder if Framework 6.1 could consider introducing relative ordering support rather than relying on the current, rather brittle, absolute values? It's served us very well for Boot's auto-configuration.

@wilkinsona wilkinsona changed the title WelcomePageHandlerMapping has higher priority than RouterFunctionMapping Order WelcomePageHandlerMapping after WebMvc.fn's RouterFunctionMapping Apr 28, 2023
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Apr 28, 2023
@wilkinsona wilkinsona added this to the 3.2.x milestone Apr 28, 2023
@sdeleuze
Copy link
Contributor Author

I will discuss that with the Framework team and let you know if the rest of the team is ok with that.

@scottfrederick scottfrederick added the status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team label May 1, 2023
@philwebb
Copy link
Member

philwebb commented Jun 6, 2023

@sdeleuze Any update from the Framework team?

@sdeleuze
Copy link
Contributor Author

sdeleuze commented Jun 7, 2023

We have discussed this topic in this week Spring Framework team meeting, the follow-up discussion is still ongoing. I will post an update here as soon as we have reached a consensus (should happen shortly).

@sdeleuze
Copy link
Contributor Author

sdeleuze commented Jun 12, 2023

As mentioned in spring-framework#30278:

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).

This change will likely solve in Spring Boot 3.2 the original issue reported here. Solving it in Spring Boot 3.1 would require changing the WelcomePageHandlerMapping order to a lower priority order (at least 4). I think I would be in favor of that, but of course, up to Spring Boot team to decide if that's desirable and ok to perform this kind of post 3.1.0 adjustements or not.

I wonder if Framework 6.1 could consider introducing relative ordering support rather than relying on the current, rather brittle, absolute values? It's served us very well for Boot's auto-configuration.

That would be a distinct new feature that would require careful design consideration, so unlikely to be shipped as part of Spring Framework 6.1 given our current priorities.

@wilkinsona wilkinsona removed the status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team label Jun 23, 2023
@bclozel bclozel self-assigned this Sep 8, 2023
@bclozel
Copy link
Member

bclozel commented Sep 11, 2023

I've tested successfully the Spring Framework change from spring-projects/spring-framework#30278 - the custom RouterFunction for the index page is properly ordered ahead of the welcome page support.

Let's rework this issue as a documentation one to properly document the ordering in the welcome page section of web frameworks.

@bclozel bclozel added type: documentation A documentation update and removed type: enhancement A general enhancement labels Sep 11, 2023
@bclozel bclozel modified the milestones: 3.2.x, 3.2.0-M3 Sep 11, 2023
@wilkinsona wilkinsona changed the title Order WelcomePageHandlerMapping after WebMvc.fn's RouterFunctionMapping Document Welcome Page support ordering Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

7 participants