Adding custom functionality to all repositories

Sometimes we have to add custom functionality to all repositories. In this section, we will learn how we can do this and create a custom repository method that is used to delete an entity by using its ID.

We can add custom functionality to all repositories by following these steps:

  1. Create a base interface that declares the custom methods.
  2. Implement the created interface.
  3. Create a repository factory bean.
  4. Configure Spring Data JPA to use our repository factory bean.
  5. Create a repository interface.
  6. Implement a service class that uses the custom functionality.

Creating the base repository interface

We start by creating a base repository interface that declares the methods that are available in the actual repositories. ...

Get Spring Data now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.