简体   繁体   English

"Spring 中的@Repository 和@RepositoryDe​​finition 有什么区别?"

[英]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 or PagingAndSortingRepository . 通常,您的存储库接口将扩展RepositoryCrudRepositoryPagingAndSortingRepository 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 extending Repository . RepositoryDefinition注释接口将导致与扩展Repository相同的行为。

You might be interested in Using @RepositoryDefinition and JpaSpecificationExecutor methods doesn't work too. 您可能对使用@RepositoryDe​​finition和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>

Annotation to demarcate interfaces a repository proxy shall be created for.应创建用于划分存储库代理的接口的注释。 Annotating an interface with RepositoryDefinition will cause the same behaviour as extending Repository.使用 RepositoryDe​​finition 注释接口将导致与扩展 Repository 相同的行为。

<\/blockquote>

This means that and interface annotated with RepositoryDefinition will create a proxy to execute the query methods of the interface这意味着使用 RepositoryDe​​finition 注释的接口将创建一个代理来执行接口的查询方法

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 中的@Component、@Repository 和@Service 注解有什么区别? - What's the difference between @Component, @Repository & @Service annotations in Spring? Seedstack 中的 Repository 和 Finder 有什么区别? - What's the difference between a Repository and a Finder in Seedstack? 与使用存储库相比,使用服务有什么区别? Spring 开机 - What's the difference between using a Service compared to using a repository? Spring Boot Spring CGLIB 和 CGLIB 有什么区别? - What's the difference between Spring CGLIB and CGLIB? 春天的@Named和@Qualifier有什么区别 - What's the difference between @Named and @Qualifier in spring 如何处理@Component和@Repository / @Service注释之间的区别是什么? - What's the difference between how @Component and @Repository / @Service annotations are processed? Spring中ResponseEntity和HttpEntity有什么区别? - What's the difference between ResponseEntity and HttpEntity in Spring? Spring BeanFactoryAware和ApplicationContextAware有什么区别? - What's the difference between Spring BeanFactoryAware and ApplicationContextAware? 春天的form:form和sf:form有什么区别? - What’s the difference between form:form and sf:form in spring? 托管bean和spring控制器有什么区别? - what's the difference between managed bean and spring controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM