最近工作中用到了spring data JPA,看官方文档有个@NoRepositoryBean,说说自己的理解。
官方文档:
The intermediate repository interface is annotated with @NoRepositoryBean. Make sure you add that annotation to all repository interfaces for which Spring Data should not create instances at runtime.
大概意思就是: 中间存储库接口用注释@NoRepositoryBean。确保将注释添加到所有存储库接口,Spring Data不应在运行时为其创建实例。
我的理解就是:
在做项目时创建对象的功能会交给Spring去管理在扫描Reposytory层包时会扫描到BaseReposytory接口 ;
所有对象类接口都会继承此接口 为了告诉JPA不要创建对应接口的bean对象 就在类上加注解@NoRepositoryBean
这样spring容器中就不会有BaseReposytory接口的bean对象
@NoRepositoryBean
public interface JpaRepository<T, ID> extends PagingAndSortingRepository<T, ID>, QueryByExampleExecutor<T> {}