-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
When using UrlHandlerFilter.trailingSlashHandler() to restore the deprecated trailing slash behavior, requests are not properly handled for endpoints that explicitly define @GetMapping("/") under a @RequestMapping base path.
Expected behavior:
Both /base-path and /base-path/ should return a successful response when using the trailing slash handler filter.
Actual behavior:
Neither /base-path nor /base-path/ works - both return 404. The endpoint is not registered at all when the controller method is annotated with @GetMapping("/"). If the filter is not applied, then the path with trailing slash works, but when applied, neither works.
Minimal reproduction:
@RestController
@RequestMapping("/base-path")
static class SegmentedTestController {
// This does NOT work - both /base-path and /base-path/ return 404
@GetMapping("/")
public String getBasePath() {
return "base-path";
}
}Workaround:
@RestController
@RequestMapping("/base-path")
static class SegmentedTestController {
// This WORKS - /base-path returns 200, /base-path/ also works with filter
@GetMapping
public String getBasePath() {
return "base-path";
}
}Filter configuration:
@Bean
UrlHandlerFilter trailingSlashRedirectFilter() {
return UrlHandlerFilter.trailingSlashHandler("/**")
.wrapRequest()
.build();
}Environment:
- Spring Framework version: tested with 6.2.x and 7.0x
Analysis:
It appears that @GetMapping("/") combined with @RequestMapping("/base-path") does not properly register the endpoint, whereas @GetMapping (without the explicit / value) does. The deprecated setUseTrailingSlashMatch(true) behavior handled both cases identically.