While working on https://github.com/spring-projects/spring-framework/issues/25100 to optimize what UrlPathHelper
does based on Servlet 4.0 runtime knowledge of the Servlet mapping type I realized that Spring Boot which I believe is aware of the DispatcherServlet mapping pattern, could use that knowledge to configure UrlPathHelper
with alwaysUseFullPath=true
.
This can be done if the Servlet mapping is "/"
, or "/*"
which avoids unnecessary overhead to determine the servletPath as described in the referenced issue, essentially the same benefit that Servlet 4.0 HttpServletMapping brings but based on Boot's knowledge of the Servlet mapping instead. The only Servlet mapping type for which the servletPath must be determined is where there is a path prefix, e.g. "/myServlet/*"
which is less common.
Keep in mind that HttpServletMapping
is not supported everywhere, notably Jetty 9.x does not have Servlet 4.0 support, so this change should bring extra mileage there.
Comment From: rstoyanchev
Actually it looks like since #13292, a "/*"
mapping is not even allowed. So it's either default Servlet "/"
or a path prefix mapping "/acme/*
.