Spring MVC - URI suffix pattern matching behavior, Using setUseSuffixPatternMatch() method of RequestMappingHandlerMapping

[Updated: Mar 6, 2018, Created: Mar 3, 2018]

In this example, we will understand the effect of using method setUseRegisteredSuffixPatternMatch() of RequestMappingHandlerMapping. This flag specifies whether to use suffix pattern match (".*"). The default value is true, that means a handler with /xyz will also be mapped with / or / etc. Note that ".*" does not mean that it will also match xyzabc (there has to be a dot after xyz).


A controller

public class MyController {

  public String employeeHandler(HttpServletRequest request) {
      String uri = request.getRequestURI();
      return "from employeeHandler, uri: " + uri;

Java Config:

First we are going to see the default behavior when setUseRegisteredSuffixPatternMatch is set to true.

public class AppConfig{

To try examples, run embedded tomcat (configured in pom.xml of example project below):

mvn tomcat7:run-war


As seen in above outputs, all paths are mapped to our single handler method employeeHandler().

Setting UseSuffixPatternMatch=false

Let's configure RequestMappingHandlerMapping with the desired setting:

public class AppConfig {

    public HandlerMapping requestMappingHandlerMapping() {
        RequestMappingHandlerMapping mapping = new RequestMappingHandlerMapping();
        return mapping;


As seen above suffix matching doesn't work anymore.


In above example, we can also configure the desired flag by implementing WebMvcConfigurer (which is the preferred way as it does not override the defaults):

public class AppConfig implements WebMvcConfigurer{

  public void configurePathMatch(PathMatchConfigurer configurer) {

Example Project

Dependencies and Technologies Used:

  • spring-webmvc 5.0.4.RELEASE: Spring Web MVC.
  • javax.servlet-api 3.0.1 Java Servlet API
  • JDK 1.8
  • Maven 3.3.9

Spring Use Suffix Pattern Match Example Select All Download
  • spring-use-suffix-pattern-example
    • src
      • main
        • java
          • com
            • logicbig
              • example

See Also