Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

264
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda