Description
Previously, I was able to disable Spring MVC's trailing slash matching using something like this:
@Configuration(proxyBeanMethods = false)
class WebMvcConfiguration {
@Bean
WebMvcRegistrations webMvcRegistrations() {
return new WebMvcRegistrations() {
@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
RequestMappingHandlerMapping handlerMapping = new RequestMappingHandlerMapping();
handlerMapping.setUseTrailingSlashMatch(false);
return handlerMapping;
}
};
}
}
This doesn't work any more since 2.6.0
and the change of behavior appears to be related to introduction of PathPatternParser
as the default path matching strategy.
I've put together a reproduced in https://github.com/vpavic/mcve-spring-mvc-trailing-slash.
By default, trailing slash matching is enabled and curl -sv -u user:password http://localhost:8080/resources/
(note the trailing slash) returns 200
response. There are two profiles that disable trailing slash matching - configurer
and registrations
. The former uses WebMvcConfigurer
based approach and this works (meaning, cURL request returns 404
), while the latter uses WebMvcRegistrations
based approach (as in the snippet above) and this doesn't work (returns 200
).
Downgrading Spring Boot to 2.5.x
makes the registrations
profile work as expected.
I'm reporting this here for starters because what's failing is a Spring Boot specific configuration mechanism (WebMvcRegistrations
) even though it seems to me that the fix might very well be needed in the Framework.