Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-756

Improve the process of implementation detection for a custom method

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Repositories

      Description

      According to the Spring data documentation, when you want to add a custom behavior you have to :

      • create an interface with your custom method
      • extends the interface in the spring data repository
      • create the implementation of your custom method with a specific name : the name of the repository interface + the Impl postfix

      changes required :

      • be able to annotate the implementation of the interface which contains the custom method, to be able to give the name you want for the implementation class.

      For example, if i have a Spring data repository UserRepository with a custom behavior declared in a SearchRepository interface

      public interface UserRepository extends JpaRepository<User, Integer>, SearchRepository<User> {}
      
      public interface SearchRepository<T> {
          List<T> search(String query);
      }
      

      I would be able to give a name for my implementation like i want (and not UserRepositoryImpl) and add an annotation to declare that is the implementation of a custom method for the UserRepository.

      @RepositoryImplementation(repository = UserRepository.class)
      public class UserSearchRepository implements SearchRepository<User> {
      
          @Override
          public List<User> search(String query) {
              // doing stuff
          }
      }
      

      I think create a pull request if you're ok with the improvement

        Attachments

          Activity

            People

            Assignee:
            mp911de Mark Paluch
            Reporter:
            herau Aurélien Leboulanger
            Last updater:
            Mark Paluch
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: