You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Links to RepositoryRestController methods ignore basePath #2509
I use RepositoryRestController to add addititional resource methods to Spring Data Rest Entities. When I try to add links for them to my URI space using linkTo(methodOn(Controller.class).someMethod(), Spring Data Rest generates a URL without the configured basePath.
This issue still exists in SDR 5.0.7 / Current Codebase
How the routing side works (correctly)
BasePathAwareHandlerMapping.getMappingForMethod()does prepend the basePath to the registered request mapping patterns at handler-mapping time. So incoming HTTP requests to /api/myentities/custom are correctly routed to the @RepositoryRestController method. This part works.
How the link-generation side works (which is broken)
WebMvcLinkBuilder.linkTo(methodOn(...)) from Spring HATEOAS works by introspecting the @RequestMapping annotation on the controller method and building a URI from it. It does not consult the SDR BasePathAwareHandlerMapping or the SDR basePath configuration. It only sees the raw @RequestMapping("/myentities/custom") value on the method — without the base path prefix.
There is no mechanism in the SDR codebase that registers the base-path-augmented mappings with Spring HATEOAS's WebMvcLinkBuilder infrastructure. The RepositoryRestMvcConfiguration sets up a DelegatingHandlerMapping with the BasePathAwareHandlerMapping, but Spring HATEOAS's WebMvcLinkBuilder uses its own MvcUriComponentsBuilder which reads annotations directly from the controller class, bypassing SDR's handler mapping entirely.
No fix was introduced in 5.0.7
The git log for the 5.0.7 release (d89ecee2) shows only a version bump commit — no changes to BasePathAwareHandlerMapping, RepositoryRestController, RepositoryRestMvcConfiguration, or any link-building infrastructure. There is no commit in the history that addresses issue #2509.
Root Cause Summary
Aspect
Status
Routing of requests to @RepositoryRestController (includes basePath)
✅ Works
WebMvcLinkBuilder.linkTo(methodOn(...)) including basePath
❌ Broken
Fix present in 5.0.7
❌ No
Fix present in current main (5.2.0-SNAPSHOT)
❌ No
Recommended Workaround (still valid)
Use RepositoryEntityLinks (or EntityLinks) to build links, which correctly uses the BaseUri:
Activity
ruthst00 commentedon Sep 18, 2026
This issue still exists in SDR 5.0.7 / Current Codebase
How the routing side works (correctly)
BasePathAwareHandlerMapping.getMappingForMethod()does prepend thebasePathto the registered request mapping patterns at handler-mapping time. So incoming HTTP requests to/api/myentities/customare correctly routed to the@RepositoryRestControllermethod. This part works.How the link-generation side works (which is broken)
WebMvcLinkBuilder.linkTo(methodOn(...))from Spring HATEOAS works by introspecting the@RequestMappingannotation on the controller method and building a URI from it. It does not consult the SDRBasePathAwareHandlerMappingor the SDRbasePathconfiguration. It only sees the raw@RequestMapping("/myentities/custom")value on the method — without the base path prefix.There is no mechanism in the SDR codebase that registers the base-path-augmented mappings with Spring HATEOAS's
WebMvcLinkBuilderinfrastructure. TheRepositoryRestMvcConfigurationsets up aDelegatingHandlerMappingwith theBasePathAwareHandlerMapping, but Spring HATEOAS'sWebMvcLinkBuilderuses its ownMvcUriComponentsBuilderwhich reads annotations directly from the controller class, bypassing SDR's handler mapping entirely.No fix was introduced in 5.0.7
The git log for the 5.0.7 release (
d89ecee2) shows only a version bump commit — no changes toBasePathAwareHandlerMapping,RepositoryRestController,RepositoryRestMvcConfiguration, or any link-building infrastructure. There is no commit in the history that addresses issue #2509.Root Cause Summary
@RepositoryRestController(includes basePath)WebMvcLinkBuilder.linkTo(methodOn(...))including basePathmain(5.2.0-SNAPSHOT)Recommended Workaround (still valid)
Use
RepositoryEntityLinks(orEntityLinks) to build links, which correctly uses theBaseUri:Or manually prepend the base path:
cc @odrotbohm
Fix spring-projectsGH-2509: WebMvcLinkBuilder.linkTo() for @Repositor…