Spring data repository works without annotations

Probably you are using Spring Boot.

Spring Data repositories usually extend from the Repository or CrudRepository interfaces. If you use auto-configuration, repositories are searched from the package containing your main configuration class (the one annotated with @EnableAutoConfiguration or @SpringBootApplication) down.

Please check the Spring Boot Reference Documentation (v2.7.2) for more details.


For more information look into these class which is used to auto-configure Spring Data JPA Repositories:

JpaRepositoriesAutoConfigureRegistrar

Docs : http://www.atetric.com/atetric/javadoc/org.springframework.boot/spring-boot-autoconfigure/1.2.0.RELEASE/org/springframework/boot/autoconfigure/data/jpa/JpaRepositoriesAutoConfigureRegistrar.html

    @EnableJpaRepositories
    private static class EnableJpaRepositoriesConfiguration {

    }

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