Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

263
Vistas
Using repository annotation when implementing JpaRepostiory in Spring

I'm not sure if I understand it correctly so want to clarify. If I want to create a repository for my entity eg.:

public interface BookRepository extends JpaRepository<Book, Id> {}

Should I annotate it with @Repository? According to this question @Repository annotation translates exceptions from SQL to persistence ones but doesn't JpaRepostiory already do that? What's the best practice - to annotate or not?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

While using JpaRepository you don't need to annotate the interface with @Repository

It is just an interface and the concrete implementation is created dynamically as a proxy object by Spring and the JDBC Exceptions are handled there.

You need to use @Repository when you create a Custom DAO, so that spring creates a bean and handles the exception properly.

about 4 years ago · Santiago Trujillo Denunciar

0

You need to annotate it with @Repository so spring knows it should instantiate that class as a bean. The @Component, @Service and @Repository annotations all serve the same purpose in that regard. @Repository narrows the scope to a service that specifically deals with obtaining and storing data.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda