Affects: Spring MVC 5.3.0-M2


https://github.com/spring-projects/spring-framework/commit/567265123b738045db4808960331812adc3a7aab Changed @PathVariable at the end of the path to include the extension.

For example:

@RestController
public class SampleController {

  @GetMapping("/{str}"}
  public String sample(@PathVariable("str") String str) {
    return str;
  }
}

When request to /hoge, path variable is hoge. When request to /hoge.html, I expected hoge but actual hoge.html.

To map the request with or without extension, I need to make the following changes.

@RestController
public class SampleController {

  @GetMapping({ "/{str}", "/{str}.*" }}
  public String sample(@PathVariable("str") String str) {
    return str;
  }
}

Is this an intentional design change? or a bug?

Regards.

Comment From: bclozel

I don't think the commit you're pointing at is really related to the behavior change. This commit merely avoids creating patterns for static strings - whether or not suffix match is performed is a different matter.

See this note in the reference documentation and the related issue.

Comment From: yoshikawaa

@bclozel Thanks. The changes occured at the point you mention.

I understood the solutions are follows:

  1. Use suffix pattern (via XML)
    <mvc:annotation-driven>
        <mvc:path-matching suffix-pattern="true" />
    </mvc:annotation-driven>
  1. Not use suffix pattern, and Map specific path with or without extension
@GetMapping({ "/{str}", "/{str}.*" }}

And I also understood the file extension mapping strategy is deprecated.