Spring data repository works without annotations

前端 未结 3 1310
花落未央
花落未央 2020-12-03 22:58

I\'m using Spring Data JPA repositories (like MyRepo extends JpaRepository) and it works without @Repository and without @EnableJpaRepositori

3条回答
  •  抹茶落季
    2020-12-03 23:17

    you don't need @Repository to make use of Spring Data JPA. The Interface extending the CrudRepository or JPARepository would work even without annotating it with @Repository. The Core reason why you need to have this annotation in place is it makes unchecked exceptions thrown in the DAO layer eligible to be translated into Spring DataAccessException. Which in turn would be easier to work with. This is the important aspect of using @Repository

    More details see this -> https://www.youtube.com/watch?v=z2re1MfWtz0&list=PLO0KWyajXMh4fGMvAw1yQ1x7mWayRcmX3&index=8&t=0s

提交回复
热议问题