You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/data/nosql.adoc
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -146,7 +146,7 @@ You could take the JPA example from earlier and, assuming that `City` is now a M
146
146
include::code:CityRepository[]
147
147
148
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.
149
+
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
150
150
You can customize the locations to look for repositories and documents by using `@EnableMongoRepositories` and `@EntityScan` respectively.
151
151
152
152
TIP: For complete details of Spring Data MongoDB, including its rich object mapping technologies, see its {spring-data-mongodb}[reference documentation].
@@ -223,7 +223,7 @@ Spring Boot supports both classic and reactive Neo4j repositories, using the `Ne
223
223
When Project Reactor is available on the classpath, the reactive style is also auto-configured.
224
224
225
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.
226
+
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
227
227
You can customize the locations to look for repositories and entities by using `@EnableNeo4jRepositories` and `@EntityScan` respectively.
228
228
229
229
[NOTE]
@@ -355,7 +355,7 @@ In fact, both Spring Data JPA and Spring Data Elasticsearch share the same commo
355
355
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.
356
356
357
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.
358
+
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
359
359
You can customize the locations to look for repositories and documents by using `@EnableElasticsearchRepositories` and `@EntityScan` respectively.
360
360
361
361
TIP: For complete details of Spring Data Elasticsearch, see the {spring-data-elasticsearch-docs}[reference documentation].
@@ -445,7 +445,7 @@ Spring Data includes basic repository support for Cassandra.
445
445
Currently, this is more limited than the JPA repositories discussed earlier and needs to annotate finder methods with `@Query`.
446
446
447
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.
448
+
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
449
449
You can customize the locations to look for repositories and entities by using `@EnableCassandraRepositories` and `@EntityScan` respectively.
450
450
451
451
TIP: For complete details of Spring Data Cassandra, see the https://docs.spring.io/spring-data/cassandra/docs/[reference documentation].
@@ -500,7 +500,7 @@ To take more control, one or more `ClusterEnvironmentBuilderCustomizer` beans ca
500
500
Spring Data includes repository support for Couchbase.
501
501
502
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.
503
+
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
504
504
You can customize the locations to look for repositories and documents by using `@EnableCouchbaseRepositories` and `@EntityScan` respectively.
505
505
506
506
For complete details of Spring Data Couchbase, see the {spring-data-couchbase-docs}[reference documentation].
@@ -570,7 +570,7 @@ Make sure to flag your customized `ContextSource` as `@Primary` so that the auto
570
570
Spring Data includes repository support for LDAP.
571
571
572
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.
573
+
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
574
574
You can customize the locations to look for repositories and documents by using `@EnableLdapRepositories` and `@EntityScan` respectively.
575
575
576
576
For complete details of Spring Data LDAP, see the https://docs.spring.io/spring-data/ldap/docs/1.0.x/reference/html/[reference documentation].
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/data/sql.adoc
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -195,7 +195,7 @@ You can follow the https://spring.io/guides/gs/accessing-data-jpa/["`Accessing D
195
195
==== Entity Classes
196
196
Traditionally, JPA "`Entity`" classes are specified in a `persistence.xml` file.
197
197
With Spring Boot, this file is not necessary and "`Entity Scanning`" is used instead.
198
-
By default, all packages below your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) are searched.
198
+
By default the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
199
199
200
200
Any classes annotated with `@Entity`, `@Embeddable`, or `@MappedSuperclass` are considered.
201
201
A typical entity class resembles the following example:
@@ -216,7 +216,7 @@ For example, a `CityRepository` interface might declare a `findAllByState(String
216
216
For more complex queries, you can annotate your method with Spring Data's {spring-data-jpa-api}/repository/Query.html[`Query`] annotation.
217
217
218
218
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.
219
-
If you use auto-configuration, repositories are searched from the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) down.
219
+
If you use auto-configuration, the <<using#using.auto-configuration.packages,auto-configuration packages>> are searched for repositories.
220
220
221
221
TIP: You can customize the locations to look for repositories using `@EnableJpaRepositories`.
222
222
@@ -506,7 +506,7 @@ For example, a `CityRepository` interface might declare a `findAllByState(String
506
506
For more complex queries, you can annotate your method with Spring Data's {spring-data-r2dbc-api}/repository/Query.html[`Query`] annotation.
507
507
508
508
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.
509
-
If you use auto-configuration, repositories are searched from the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) down.
509
+
If you use auto-configuration, the <<using#using.auto-configuration.packages,auto-configuration packages>> are searched for repositories.
510
510
511
511
The following example shows a typical Spring Data repository interface definition:
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/data-access.adoc
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -150,23 +150,23 @@ Note that each `configuration` sub namespace provides advanced settings based on
150
150
[[howto.data-access.spring-data-repositories]]
151
151
=== Use Spring Data Repositories
152
152
Spring Data can create implementations of `@Repository` interfaces of various flavors.
153
-
Spring Boot handles all of that for you, as long as those `@Repositories` are included in the same package (or a sub-package) of your `@EnableAutoConfiguration` class.
153
+
Spring Boot handles all of that for you, as long as those `@Repositories` are included in one of the <<using#using.auto-configuration.packages,auto-configuration packages>>, typically the package (or a sub-package) of your main application class that is annotated with `@SpringBootApplication` or `@EnableAutoConfiguration`.
154
154
155
155
For many applications, all you need is to put the right Spring Data dependencies on your classpath.
156
156
There is a `spring-boot-starter-data-jpa` for JPA, `spring-boot-starter-data-mongodb` for Mongodb, and various other starters for supported technologies.
157
157
To get started, create some repository interfaces to handle your `@Entity` objects.
158
158
159
-
Spring Boot tries to guess the location of your `@Repository` definitions, based on the `@EnableAutoConfiguration` it finds.
160
-
To get more control, use the `@EnableJpaRepositories` annotation (from Spring Data JPA).
159
+
Spring Boot determines the location of your `@Repository` definitions by scanning the <<using#using.auto-configuration.packages,auto-configuration packages>>.
160
+
For more control, use the `@Enable…Repositories` annotations from Spring Data.
161
161
162
162
For more about Spring Data, see the {spring-data}[Spring Data project page].
=== Separate @Entity Definitions from Spring Configuration
168
-
Spring Boot tries to guess the location of your `@Entity` definitions, based on the `@EnableAutoConfiguration` it finds.
169
-
To get more control, you can use the `@EntityScan` annotation, as shown in the following example:
168
+
Spring Boot determines the location of your `@Entity` definitions by scanning the <<using#using.auto-configuration.packages,auto-configuration packages>>.
169
+
For more control, use the `@EntityScan` annotation, as shown in the following example:
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/using/auto-configuration.adoc
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,3 +35,10 @@ TIP: You can define exclusions both at the annotation level and by using the pro
35
35
36
36
NOTE: Even though auto-configuration classes are `public`, the only aspect of the class that is considered public API is the name of the class which can be used for disabling the auto-configuration.
37
37
The actual contents of those classes, such as nested configuration classes or bean methods are for internal use only and we do not recommend using those directly.
38
+
39
+
40
+
[[using.auto-configuration.packages]]
41
+
=== Auto-configuration Packages
42
+
Auto-configuration packages are the packages that various auto-configured features look in by default when scanning for things such as entities and Spring Data repositories.
43
+
The `@EnableAutoConfiguration` annotation (either directly or through its presence on `@SpringBootApplication`) determines the default auto-configuration package.
44
+
Additional packages can be configured using the `@AutoConfigurationPackage` annotation.
0 commit comments