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.
Previously, I was able to disable Spring MVC's trailing slash matching using something like this:
This doesn't work any more since
2.6.0and the change of behavior appears to be related to introduction ofPathPatternParseras 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) returns200response. There are two profiles that disable trailing slash matching -configurerandregistrations. The former usesWebMvcConfigurerbased approach and this works (meaning, cURL request returns404), while the latter usesWebMvcRegistrationsbased approach (as in the snippet above) and this doesn't work (returns200).Downgrading Spring Boot to
2.5.xmakes theregistrationsprofile 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.