Conversation
Signed-off-by: ruthes00 <ruthes00@gmail.com>
…yRestController ignores basePath Introduce BasePathAwareWebMvcLinkBuilderFactory, a WebMvcLinkBuilderFactory subclass that detects controllers annotated with @BasePathAwareController (which includes @RepositoryRestController) and automatically prepends the configured spring.data.rest.base-path to the generated URI. Previously, calling WebMvcLinkBuilder.linkTo(methodOn(MyController.class).method()) inside a @RepositoryRestController would produce a URL without the configured basePath (e.g. /items instead of /api/items), even though incoming requests were correctly routed via BasePathAwareHandlerMapping. The factory is registered as a Spring bean in RepositoryRestMvcConfiguration so it is available for injection and use throughout the application context. Signed-off-by: ruthes00 <ruthes00@gmail.com>
ruthst00
force-pushed
the
issue/2509
branch
from
September 18, 2026 09:28
640fee0 to
33753ad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes 2509
What was implemented
1.
BasePathAwareWebMvcLinkBuilderFactory.java(new)A
WebMvcLinkBuilderFactorysubclass that overrideslinkTo(Object invocationValue). When the target controller is annotated with@BasePathAwareController(which@RepositoryRestControlleris a meta-annotation of), it intercepts theWebHandler.linkTo()call and provides a customfinisherfunction that prepends the configuredbasePathto the mapping path before building theUriComponentsBuilder. It uses reflection to access the package-privateWebMvcLinkBuilder(UriComponents, TemplateVariables, List<Affordance>)constructor so the returned type is still a properWebMvcLinkBuilder.2.
RepositoryRestMvcConfiguration.java(modified)Registers
BasePathAwareWebMvcLinkBuilderFactoryas a@BeannamedbasePathAwareWebMvcLinkBuilderFactory, injecting theRepositoryRestConfiguration. Added@author Steve Rutherfordto the class Javadoc.3.
BasePathAwareWebMvcLinkBuilderFactoryUnitTests.java(new)5 unit tests covering:
@BasePathAwareControllergets base path prepended ✅@RepositoryRestControllergets base path prepended ✅