[英]What's the difference between @Repository and @RepositoryDefinition in Spring?
I'd want to know the difference between @Repository
and @RepositoryDefinition
in Spring.我想知道 Spring 中
@Repository
和@RepositoryDefinition
之间的区别。 And which would take in effect with @EnableNeo4jRepositories
?哪个会与
@EnableNeo4jRepositories
一起生效?
I can't answer in regard to Neo4j, but deciding between the two Spring annotations is a design decision. 对于Neo4j,我无法回答,但是在两个Spring注释之间做出决定是一项设计决定。 I'll quote from the official documentation :
我将引用官方文档 :
Typically, your repository interface will extend
Repository
,CrudRepository
orPagingAndSortingRepository
.通常,您的存储库接口将扩展
Repository
,CrudRepository
或PagingAndSortingRepository
。 Alternatively, if you do not want to extend Spring Data interfaces, you can also annotate your repository interface with@RepositoryDefinition
.另外,如果您不想扩展Spring Data接口,也可以使用
@RepositoryDefinition
注释存储库接口。
The API doc is even more clear: API文档更加清晰:
Annotating an interface with
RepositoryDefinition
will cause the same behaviour as extendingRepository
.用
RepositoryDefinition
注释接口将导致与扩展Repository
相同的行为。
You might be interested in Using @RepositoryDefinition and JpaSpecificationExecutor methods doesn't work too. 您可能对使用@RepositoryDefinition和JpaSpecificationExecutor方法不起作用感兴趣。
@Repository is an annotation that tells spring to create a Bean, hence, it needs to be put on a Class. @Repository 是一个注解,它告诉 spring 创建一个 Bean,因此,它需要放在一个类上。 It similar to @Service or @RestController but with some peculiarities regarding the Transactional behaviour and exception handling (annotated classes can be chosen for PersistenceExceptionTranslationPostProcessor).
它类似于@Service 或@RestController,但在事务行为和异常处理方面有一些特殊性(可以为 PersistenceExceptionTranslationPostProcessor 选择带注释的类)。 It can be seen as specialization of @Component
它可以看作是@Component 的特化
@Repository definition, according to the doc<\/a> @Repository 定义,根据
文档<\/a>
<\/blockquote>
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.