Annotation Interface EnableJpaRepositories
@Target(TYPE)
@Retention(RUNTIME)
@Documented
@Import(org.springframework.data.jpa.repository.config.JpaRepositoriesRegistrar.class)
public @interface EnableJpaRepositories
Annotation to enable JPA repositories. Will scan the package of the annotated configuration class for Spring Data
repositories by default.
- Author:
- Oliver Gierke, Thomas Darimont, Greg Turnquist
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionClass<?>[]
Type-safe alternative tobasePackages()
for specifying the packages to scan for annotated components.String[]
Base packages to scan for annotated components.Configures when the repositories are initialized in the bootstrap lifecycle.boolean
Configures whether nested repository-interfaces (e.g. defined as inner classes) should be discovered by the repositories infrastructure.boolean
Configures whether to enable default transactions for Spring Data JPA repositories.Configures the name of theEntityManagerFactory
bean definition to be used to create repositories discovered through this annotation.char
Configures what character is used to escape the wildcards _ and % in derived queries with contains, startsWith or endsWith clauses.Specifies which types are not eligible for component scanning.Specifies which types are eligible for component scanning.Configures the location of where to find the Spring Data named queries properties file.Returns the key of theQueryLookupStrategy
to be used for lookup queries for query methods.Class<?>
Configure the repository base class to be used to create repository proxies for this particular configuration.Class<?>
Returns theFactoryBean
class to be used for each repository instance.Returns the postfix to be used when looking up custom repository implementations.Configures the name of thePlatformTransactionManager
bean definition to be used to create repositories discovered through this annotation.String[]
Alias for thebasePackages()
attribute.
-
Element Details
-
value
String[] valueAlias for thebasePackages()
attribute. Allows for more concise annotation declarations e.g.:@EnableJpaRepositories("org.my.pkg")
instead of@EnableJpaRepositories(basePackages="org.my.pkg")
.- Default:
- {}
-
basePackages
String[] basePackagesBase packages to scan for annotated components.value()
is an alias for (and mutually exclusive with) this attribute. UsebasePackageClasses()
for a type-safe alternative to String-based package names.- Default:
- {}
-
basePackageClasses
Class<?>[] basePackageClassesType-safe alternative tobasePackages()
for specifying the packages to scan for annotated components. The package of each class specified will be scanned. Consider creating a special no-op marker class or interface in each package that serves no purpose other than being referenced by this attribute.- Default:
- {}
-
includeFilters
ComponentScan.Filter[] includeFiltersSpecifies which types are eligible for component scanning. Further narrows the set of candidate components from everything inbasePackages()
to everything in the base packages that matches the given filter or filters.- Default:
- {}
-
excludeFilters
ComponentScan.Filter[] excludeFiltersSpecifies which types are not eligible for component scanning.- Default:
- {}
-
repositoryImplementationPostfix
String repositoryImplementationPostfixReturns the postfix to be used when looking up custom repository implementations. Defaults to Impl. So for a repository namedPersonRepository
the corresponding implementation class will be looked up scanning forPersonRepositoryImpl
.- Returns:
- Default:
- "Impl"
-
namedQueriesLocation
String namedQueriesLocationConfigures the location of where to find the Spring Data named queries properties file. Will default toMETA-INF/jpa-named-queries.properties
.- Returns:
- Default:
- ""
-
queryLookupStrategy
QueryLookupStrategy.Key queryLookupStrategyReturns the key of theQueryLookupStrategy
to be used for lookup queries for query methods. Defaults toQueryLookupStrategy.Key.CREATE_IF_NOT_FOUND
.- Returns:
- Default:
- CREATE_IF_NOT_FOUND
-
repositoryFactoryBeanClass
Class<?> repositoryFactoryBeanClassReturns theFactoryBean
class to be used for each repository instance. Defaults toJpaRepositoryFactoryBean
.- Returns:
- Default:
- org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.class
-
repositoryBaseClass
Class<?> repositoryBaseClassConfigure the repository base class to be used to create repository proxies for this particular configuration.- Returns:
- Since:
- 1.9
- Default:
- org.springframework.data.repository.config.DefaultRepositoryBaseClass.class
-
entityManagerFactoryRef
String entityManagerFactoryRefConfigures the name of theEntityManagerFactory
bean definition to be used to create repositories discovered through this annotation. Defaults toentityManagerFactory
.- Returns:
- Default:
- "entityManagerFactory"
-
transactionManagerRef
String transactionManagerRefConfigures the name of thePlatformTransactionManager
bean definition to be used to create repositories discovered through this annotation. Defaults totransactionManager
.- Returns:
- Default:
- "transactionManager"
-
considerNestedRepositories
boolean considerNestedRepositoriesConfigures whether nested repository-interfaces (e.g. defined as inner classes) should be discovered by the repositories infrastructure.- Default:
- false
-
enableDefaultTransactions
boolean enableDefaultTransactionsConfigures whether to enable default transactions for Spring Data JPA repositories. Defaults to true. If disabled, repositories must be used behind a facade that's configuring transactions (e.g. using Spring's annotation driven transaction facilities) or repository methods have to be used to demarcate transactions.- Returns:
- whether to enable default transactions, defaults to true.
- Default:
- true
-
bootstrapMode
BootstrapMode bootstrapModeConfigures when the repositories are initialized in the bootstrap lifecycle.BootstrapMode.DEFAULT
(default) means eager initialization except all repository interfaces annotated withLazy
,BootstrapMode.LAZY
means lazy by default including injection of lazy-initialization proxies into client beans so that those can be instantiated but will only trigger the initialization upon first repository usage (i.e a method invocation on it). This means repositories can still be uninitialized when the application context has completed its bootstrap.BootstrapMode.DEFERRED
is fundamentally the same asBootstrapMode.LAZY
, but triggers repository initialization when the application context finishes its bootstrap.- Returns:
- Since:
- 2.1
- Default:
- DEFAULT
-
escapeCharacter
char escapeCharacterConfigures what character is used to escape the wildcards _ and % in derived queries with contains, startsWith or endsWith clauses.- Returns:
- a single character used for escaping.
- Default:
- '\\'
-