spring-projects / spring-projects/spring-data-commons

Repository method override not picked up

Open
#2,888 5 comments 0 reactions 2 assignees View on GitHub

@mp911de is already working on this.

Since Aug 7, 2023.

in: kotlin status: waiting-for-triage
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.