Abhishek Ekaanth
Abhishek Ekaanth

Reputation: 2567

Spring- Difference and use case @Repository and @RepositoryRestResource?

When I started to use spring boot I was annotating my interface with @Repositoryall these days I was following the same, but today I happened to come across annotating with another way called @RepositoryRestResource. What is the difference between them, When is it used.

Upvotes: 2

Views: 2700

Answers (3)

James Mudd
James Mudd

Reputation: 2373

The @Repository annotation enables exception translation so you can handle Springs DataAccessException instead of underlying persistence implementation exceptions (via PersistenceExceptionTranslationPostProcessor). @RepositoryRestResource is not a specialization of @Repository so you might want in include both, to expose REST endpoints and enable exception translation.

Upvotes: 0

Sourabh Bhavsar
Sourabh Bhavsar

Reputation: 219

In addition to answer mentioned above, you can also customize your REST endpoints using @RepositoryRestResource.

Upvotes: 0

StanislavL
StanislavL

Reputation: 57381

@RepositoryRestResource means you have REST endpoint to the repository. So user calls it directly via REST calls.

@Repository is a marker to a component which somehow stores data (CRUD operations). It is not necessary be accessible from external users directly.

So in case of @RepositoryRestResource you don't have any controller/service/dao layers but direct access.

Upvotes: 3

Related Questions