Spring 3.1+ uses a RequestMappingHandlerMapping
to create RequestMappingInfo
objects which map your controller handler methods to their corresponding @RequestMapping
paths. When the DispatcherServlet
receives a request, it uses the RequestMappingHandlerMapping
again to determine which handler method should be used.
The way it is currently implemented, it finds all the registered RequestMappingInfo
objects that match the request and then sorts them based on a number of rules, basically those defined in AntPathMatcher
and AntPatternComparator
.
You'll have to configure your RequestMappingHandlerMapping
bean to use a custom PathMatcher
with your own rules for comparing.
How you do this depends on how you are doing your configuration. If you use a @Configuration
class, you can do
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
...
@Override
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
RequestMappingHandlerMapping mapping = super.requestMappingHandlerMapping();
mapping.setPathMatcher(pathMatcher()); // some PathMatcher bean
return mapping;
}
...
}
The RequestMappingInfo
objects created by this RequestMappingHandlerMapping
will internally use this PathMatcher
. They will be sorted based on its Comparator
.