A repository manages data persistence: it gives application logic a place to store and retrieve data without taking on database access itself. Defining a repository as an interface separates that responsibility from its implementation, so the implementation can change without changing the service that uses it. section 4.1.3 section 4.3
Publishing a comment
A CommentService publishes a comment by asking CommentRepository to store it and a notification proxy to send it. The service depends on interfaces; DBCommentRepository supplies the storage implementation. In Spring, @Repository marks the repository component and makes its role visible. section 4.1.3 section 4.3
Figure 4.6 The CommentService object depends on the abstractions provided by CommentRepository and CommentNotificationProxy interfaces. The classes DBCommentRepository and EmailCommentNotificationProxy further implement these interfaces. This design decouples the implementation of the “publish comment” use case from its dependencies and makes the application easier to change for future developments.

The diagram shows how repository and notification interfaces separate the service from replaceable implementations. section 4.1.3
Spring Data takes this further: declare repository interfaces and let the framework provide implementations at runtime. Contracts such as CrudRepository supply common operations; methods can also define custom queries with @Query or derive them from method names. section 14.0 section 14.5










