spring-projects / spring-projects/spring-data-commons
Repository method override not picked up
@mp911de is already working on this.
Since Aug 7, 2023.
- Dominant language
- Java
- Stars
- 838
- Forks
- 730
- PR merge metrics
- No merged PRs in 30d
Description
Using Spring Boot Data 3.0.6, with Kotlin.
I have a UserRepository extending a CrudRepository, with a method override
@RestResource
override fun findById(id: Long): Optional<User>
My default method exposure is disabled.
When I call my REST endpoint on /users/123 I get a 405 Method Not Allowed. If I enable method exposure, the default implementation from CrudRepository is being picked up instead of my custom declared repository method.
If I declare a custom findAll(), this gets picked up without issues.
I did some digging and it seems that in DefaultCrudMethods.selectMostSuitableFindOneMethod(...) it fails to find the custom interface method, it however does find the CrudRepository one. It calls ReflectionUtils.findMethod(UserRepository.class, "findById", Long.class), and there the comparison of parameter types somehow fails.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.