Spring Framework 5.3 introduced the PathPattern as an efficient alternative to AntPathMatcher URL matching. Spring Boot 2.4 introduced (in issue #21694) a new config property to enable the PathPattern-based URL matching; spring.mvc.pathmatch.matching-strategy=path_pattern_parser.

This works well for URL matching of @Controllers etc, but org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping does not respect the aforementioned config property - it always uses the AntPathMatcher-based URL matching. I.e. all actuator endpoints still have their URLs matched with AntPathMatcher. This is a bit painful since the WebMvcEndpointHandlerMapping typically has higher priority than the RequestMappingHandlerMapping and hence is asked to try to match every incoming request before the RequestMappingHandlerMapping gets to do its thing. I.e. every request is still matched with the AntPathMatcher even if we use spring.mvc.pathmatch.matching-strategy=path_pattern_parser.

I would expect the WebMvcEndpointHandlerMapping to respect the configuration and use the PathPattern-based URL matching in this case so that I can completely eliminate the use of AntPathMatcher.

The root cause of this seems to be that WebMvcEndpointHandlerMapping initialises its AbstractWebMvcEndpointHandlerMapping#builderConfig via a private static method that does not take any configuration into account.

In contrast RequestMappingHandlerMapping (that respects the configuration property) initialises RequestMappingHandlerMapping#config in #afterPropertiesSet() with the pattern parser typically injected via org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#configurePathMatch.

Comment From: philwebb

See also #24805

Comment From: philwebb

We might be able to share the same PathPattern instance to save memory.

Comment From: philwebb

I think it makes sense for us to completely switch our WebMvcEndpointHandlerMapping to use PathPattern rather than having it configurable. The handler mapper is an adapter to expose actuator endpoints and they already have quite tight rules around the URL patterns that are supported.

I wanted to make this change for 2.5.0.RC1, unfortunately I his a snag with https://github.com/spring-projects/spring-framework/issues/26814. The same issue has also caused us to revert #24805.

Comment From: hpoettker

This change seems to have broken compatibility with the latest release of io.springfox:springfox-boot-starter, i.e. version 3.0.0.

As springfox has not been actively maintained for a while, Spring Boot cannot be asked to actively keep up compatibility. But as springfox still seems to be popular, this might be a noteworthy remark in the release notes.

See also here: https://stackoverflow.com/questions/69108273/spring-boot-swagger-documentation-doesnt-work/69814964