Spring数据存储库无需注释即可工作 [英] Spring data repository works without annotations

查看:80
本文介绍了Spring数据存储库无需注释即可工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Data JPA存储库(例如MyRepo extends JpaRepository),它在没有@Repository和没有@EnableJpaRepositories批注的情况下也可以工作.有人可以解释为什么吗?

I'm using Spring Data JPA repositories (like MyRepo extends JpaRepository) and it works without @Repository and without @EnableJpaRepositories annotations. Could someone explain why?

推荐答案

可能您正在使用Spring Boot.

Probably you are using Spring Boot.

Spring Data存储库通常从Repository扩展,或者 CrudRepository接口.如果您使用的是自动配置, 系统将从包含您的主要存储库的软件包中搜索存储库 配置类(用@EnableAutoConfiguration注释的类 或@SpringBootApplication).

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

请检查 https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html#boot-features-spring-data-jpa-repositories 了解更多信息.

这篇关于Spring数据存储库无需注释即可工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆