-
Notifications
You must be signed in to change notification settings - Fork 560
@RepsitoryRestController adds the repository twice (under root and basePath) [DATAREST-972] #1342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Robert Rackl commented I found out one more thing. RepositoryRestController extends BasePathAwareController. If I use the |
Greg Turnquist commented
I'm not sure why we need both I DID notice that However, when forming a link using Spring HATEOAS's ControllerLinkBuilder, Spring HATEOAS doesn't have insight into the BasePathAwareHandlerMapping, and it hence unable to create a proper link. I don't know if we need to morph this issue into plans to deprecate/remove |
Greg Turnquist commented I may have uncovered where the thing is registered twice:
RespositoryRestHandlerMapping extends BasePathAwareHandlerMapping, so it's like there are two BasePathAwareHandlerMapping's being created, and getting registered. My gut says this wasn't the intended goal |
Istvan Ratkai commented nope. The controller is mapped twice because the RequestMappingHandlerMapping also maps it. Then the RepositoryRestHandlerMapping also maps it, because it maps all beans which are annotated by Try removing the class level if the controller also explicitly annotated by BasePathAwareHandlerMapping maps controller which are directly annotated by this annotation. (So if you annotate the controller ONLY with You won't get mapping conflict exception, because 1st and 2nd mappings have different path, and 2nd and 3rd mappings have different MediaType (because So... You can easily avoid using However removing the I assume that annotation is tested by the standard RequestMappingHandlerMapping because of convenient or historical reasons (You don't have to use But maybe a Spring-Guru can find a better solution... |
Istvan Ratkai commented Ouch... my workaround in the previous won't work if you want to use ControllerLinkBuilder (what is broken currently), because it gets the path from the class level |
Martin Veverka commented What about extending the RequestMaping Annotation: @RequestMapping(path="postBallotJson", doNotExposeWithoutControllerAnnotation=true) It is compatible with existing applications |
Oliver Drotbohm commented The fact that |
Martin Veverka commented No, it will not be breaking change, if it is explicitly declared by new attribute of the RequestMapping annotation. The default behavior do not change, but I will be able to say in particular usage of the RequestMapping, that I do not expose this mapping in Spring MVC |
Oliver Drotbohm commented I guess you'd have to bring that up with the Spring MVC team then but I guess you'll get puss back as declaring an attribute in a Spring MVC annotation that MVc is supposed to disregard the annotation feels a bit weird |
Doogiemuc commented My current workaround:
|
…stMapping. When we detected @BasePathAwareController and @RepositoryRestController instances, we now reject types that use @RequestMapping on the class level as doing so causes an inevitable registration of the controller with Spring MVC. Fixes #1342, #1628, #1686, #1946.
…stMapping. When we detected @BasePathAwareController and @RepositoryRestController instances, we now reject types that use @RequestMapping on the class level as doing so causes an inevitable registration of the controller with Spring MVC. Fixes #1342, #1628, #1686, #1946.
This should be resolved now. As of the next release we're going to reject type-level |
not allowed in spring-boot 2.6.0-RC1 together with @RepositoryRestController see: spring-projects/spring-data-rest#1342 (comment)
Robert Rackl opened DATAREST-972 and commented
GIVEN a spring-data-rest app, that exposes some repository as HATEOAS REST endpoints.
WHEN you now want to override the behaviour of a response handler, this is described in the spring-data doc:
http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers
BUT this does not work. Here are two related posts that describe the inconsistency:
The simplest test I could find was: When you create a controller with the
@BasePathAwareController
annotation, then@RequestMapping
at the class level ans MUST NOT set it at method / type level (which is not documented yet) for it to work at allHere is my code:
When I start the app I see in the log:
And only the resource in the root path /postBallotJson works.
Expected Behaviour
The resource with the base path prefix should be the only one and work. /liquido/v2/postBallotJson
Affects: 2.5.4 (Hopper SR4)
Reference URL: https://github.com/mike-boddin/spring-data-rest-example
6 votes, 10 watchers
The text was updated successfully, but these errors were encountered: