Repository navigation
fix(spring): skip root forwarding when Vaadin servlet is not registered - #27245
totally-not-ai[bot] wants to merge 5 commits into
Conversation
Type of changeBug fix How to test
|
|
Fixed all five in 6f9e371: the fields of |
vaadin-review-bot
left a comment
There was a problem hiding this comment.
Reviewed the changes — left 1 comment.
| Finding | |
|---|---|
| 📝 | Javadoc claims self-registration of the Vaadin servlet is what triggers the new skip, which is not what the code does. |
| * application excluded and the requests a static resource handler answers. | ||
| * <p> | ||
| * When the default forwarding controller is used and the servlet context | ||
| * has no servlet under the name it forwards to, which is the case when the |
There was a problem hiding this comment.
📝 Javadoc claims self-registration of the Vaadin servlet is what triggers the new skip, which is not what the code does.
The clause "which is the case when the application registers the Vaadin servlet itself" states an equivalence the code does not have. Both supported self-registration paths — VaadinMVCWebAppInitializer and SpringBootAutoConfiguration.configureServletRegistrationBean — register under springServlet and keep forwarding, and even a hand-built ServletRegistrationBean<SpringServlet> gets that name deduced. The actual condition is "no servlet registered under the name the controller forwards to", which the sentence already says; the added clause only misleads a reader into thinking any self-registration turns Vaadin root routing off.
VaadinServletConfiguration.java:117 · documentation
There was a problem hiding this comment.
Agreed, that clause overstated it. I removed it, so the Javadoc now states only the real condition: the mapping handles no requests when the default forwarding controller is used and no servlet is registered under the name it forwards to.
vaadin-review-bot
left a comment
There was a problem hiding this comment.
✅ Nothing to flag — the changes look good.
vaadin-review-bot
left a comment
There was a problem hiding this comment.
✅ Nothing to flag — the changes look good.
|
Artur-
left a comment
There was a problem hiding this comment.
What is the logic for registering the vaadin servlet? Isn't the forwarding related to that and we should only register it when the vaadin servlet is auto registered for /* ?
|
@Artur- The servlet is registered in two places, and
The configuration also reaches plain Spring apps through So yes, the forwarding belongs to the root-mapped servlet. The PR checks that at request time: it forwards only when a servlet named Gating the registration itself would also work, but needs more: in plain Spring the initializer would have to read the mapping before |



Fixes #27244
behavior deviation · vaadin-spring · plain Spring apps that register the Vaadin servlet themselves and don't set
vaadin.urlMappingWhen
vaadin.urlMappingisn't set,VaadinServletConfigurationassumes the Vaadin servlet is root-mapped and adds a catch-all mapping to everyDispatcherServletthat forwards unmatched requests to a servlet namedspringServlet. An app that registers its own Vaadin servlet under another name and its ownDispatcherServlet(e.g. at/api/*) got a 500 "No servlet with name 'springServlet'" for every request no controller handles, instead of a 404. The catch-all mapping now steps aside when no servlet with that name is registered.Risks:
✅ Setups where Vaadin registers the servlet itself (Spring Boot,
VaadinMVCWebAppInitializer) keep forwarding: the servlet exists there. Apps that replace thevaadinForwardingControllerbean keep the old behavior.RootExcludeHandlerreturns no handler when the default forwarding controller is used and the servlet context has no named dispatcher for its servlet name — exactly the case in which the forward would throw.The default forwarding controller is now a private subclass of
ServletForwardingControllerthat remembers the servlet name, since the Spring class has no getter for it.Chose this over also requiring the
DispatcherServletto be mapped to/: the servlet check covers the reported failure without guessing at other mappings.