Skip to content

Commit d277631

Browse files
committed
Document @EntityScan and @Enable…Repositories for tuning scanning
Closes gh-36282
1 parent 21de3fb commit d277631

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/data/nosql.adoc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ You could take the JPA example from earlier and, assuming that `City` is now a M
145145

146146
include::code:CityRepository[]
147147

148-
TIP: You can customize document scanning locations by using the `@EntityScan` annotation.
148+
Repositories and documents are found through scanning.
149+
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
150+
You can customize the locations to look for repositories and documents by using `@EnableMongoRepositories` and `@EntityScan` respectively.
149151

150152
TIP: For complete details of Spring Data MongoDB, including its rich object mapping technologies, see its {spring-data-mongodb}[reference documentation].
151153

@@ -220,7 +222,9 @@ The `spring-boot-starter-data-neo4j` "`Starter`" enables the repository support
220222
Spring Boot supports both classic and reactive Neo4j repositories, using the `Neo4jTemplate` or `ReactiveNeo4jTemplate` beans.
221223
When Project Reactor is available on the classpath, the reactive style is also auto-configured.
222224

223-
You can customize the locations to look for repositories and entities by using `@EnableNeo4jRepositories` and `@EntityScan` respectively on a `@Configuration`-bean.
225+
Repositories and entities are found through scanning.
226+
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
227+
You can customize the locations to look for repositories and entities by using `@EnableNeo4jRepositories` and `@EntityScan` respectively.
224228

225229
[NOTE]
226230
====
@@ -350,6 +354,10 @@ As with the JPA repositories discussed earlier, the basic principle is that quer
350354
In fact, both Spring Data JPA and Spring Data Elasticsearch share the same common infrastructure.
351355
You could take the JPA example from earlier and, assuming that `City` is now an Elasticsearch `@Document` class rather than a JPA `@Entity`, it works in the same way.
352356

357+
Repositories and documents are found through scanning.
358+
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
359+
You can customize the locations to look for repositories and documents by using `@EnableElasticsearchRepositories` and `@EntityScan` respectively.
360+
353361
TIP: For complete details of Spring Data Elasticsearch, see the {spring-data-elasticsearch-docs}[reference documentation].
354362

355363
Spring Boot supports both classic and reactive Elasticsearch repositories, using the `ElasticsearchRestTemplate` or `ReactiveElasticsearchTemplate` beans.
@@ -436,6 +444,10 @@ If you add your own `@Bean` of type `CassandraTemplate`, it replaces the default
436444
Spring Data includes basic repository support for Cassandra.
437445
Currently, this is more limited than the JPA repositories discussed earlier and needs to annotate finder methods with `@Query`.
438446

447+
Repositories and entities are found through scanning.
448+
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
449+
You can customize the locations to look for repositories and entities by using `@EnableCassandraRepositories` and `@EntityScan` respectively.
450+
439451
TIP: For complete details of Spring Data Cassandra, see the https://docs.spring.io/spring-data/cassandra/docs/[reference documentation].
440452

441453

@@ -486,6 +498,11 @@ To take more control, one or more `ClusterEnvironmentBuilderCustomizer` beans ca
486498
[[data.nosql.couchbase.repositories]]
487499
==== Spring Data Couchbase Repositories
488500
Spring Data includes repository support for Couchbase.
501+
502+
Repositories and documents are found through scanning.
503+
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
504+
You can customize the locations to look for repositories and documents by using `@EnableCouchbaseRepositories` and `@EntityScan` respectively.
505+
489506
For complete details of Spring Data Couchbase, see the {spring-data-couchbase-docs}[reference documentation].
490507

491508
You can inject an auto-configured `CouchbaseTemplate` instance as you would with any other Spring Bean, provided a `CouchbaseClientFactory` bean is available.
@@ -551,6 +568,11 @@ Make sure to flag your customized `ContextSource` as `@Primary` so that the auto
551568
[[data.nosql.ldap.repositories]]
552569
==== Spring Data LDAP Repositories
553570
Spring Data includes repository support for LDAP.
571+
572+
Repositories and documents are found through scanning.
573+
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
574+
You can customize the locations to look for repositories and documents by using `@EnableLdapRepositories` and `@EntityScan` respectively.
575+
554576
For complete details of Spring Data LDAP, see the https://docs.spring.io/spring-data/ldap/docs/1.0.x/reference/html/[reference documentation].
555577

556578
You can also inject an auto-configured `LdapTemplate` instance as you would with any other Spring Bean, as shown in the following example:

spring-boot-project/spring-boot-docs/src/docs/asciidoc/data/sql.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ For more complex queries, you can annotate your method with Spring Data's {sprin
218218
Spring Data repositories usually extend from the {spring-data-commons-api}/repository/Repository.html[`Repository`] or {spring-data-commons-api}/repository/CrudRepository.html[`CrudRepository`] interfaces.
219219
If you use auto-configuration, repositories are searched from the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) down.
220220

221+
TIP: You can customize the locations to look for repositories using `@EnableJpaRepositories`.
222+
221223
The following example shows a typical Spring Data repository interface definition:
222224

223225
include::code:CityRepository[]

0 commit comments

Comments
 (0)