Skip to content

Update documentation on trailing slash handling where type-level @GetMapping("/base") is combined with method level @GetMapping("/") #36198

@gustavovnicius

Description

@gustavovnicius

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.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions