@EnableJpaRepositories

作用

用于Srping JPA的代码配置,用于取代xml形式的配置文件,@EnableJpaRepositories支持的配置形式丰富多用,本篇文章详细讲解。

完整注解

@EnableJpaRepositories(
    basePackages = {},
    basePackageClasses = {},
    includeFilters = {},
    excludeFilters = {},
    repositoryImplementationPostfix = "Impl",
    namedQueriesLocation = "",//META-INF/jpa-named-queries.properties
    queryLookupStrategy=QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND, //QueryLookupStrategy.Key.x
    repositoryFactoryBeanClass=JpaRepositoryFactoryBean.class, //class
    entityManagerFactoryRef="entityManagerFactory",
    transactionManagerRef="transactionManager",
    considerNestedRepositories=false,
    enableDefaultTransactions=true
)

basePackage

用于配置扫描Repositories所在的package及子package。

//单个包
@EnableJpaRepositories(basePackages = "com.cshtong")

//多个包
@EnableJpaRepositories(basePackages = {"com.cshtong.sample.repository", "com.cshtong.tower.repository"})

basePackageClasses

指定 Repository 类

@EnableJpaRepositories(basePackageClasses =BookRepository.class)

@EnableJpaRepositories(basePackageClasses = {ShopRepository.class, OrganizationRepository.class})

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×