mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Merge branch '3.1.x'
Closes gh-38054
This commit is contained in:
commit
670adaa651
@ -201,7 +201,7 @@ You could take the JPA example from earlier and, assuming that `City` is now a M
|
||||
include::code:CityRepository[]
|
||||
|
||||
Repositories and documents are found through scanning.
|
||||
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
|
||||
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
|
||||
You can customize the locations to look for repositories and documents by using `@EnableMongoRepositories` and `@EntityScan` respectively.
|
||||
|
||||
TIP: For complete details of Spring Data MongoDB, including its rich object mapping technologies, see its {spring-data-mongodb}[reference documentation].
|
||||
@ -257,7 +257,7 @@ Spring Boot supports both classic and reactive Neo4j repositories, using the `Ne
|
||||
When Project Reactor is available on the classpath, the reactive style is also auto-configured.
|
||||
|
||||
Repositories and entities are found through scanning.
|
||||
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
|
||||
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
|
||||
You can customize the locations to look for repositories and entities by using `@EnableNeo4jRepositories` and `@EntityScan` respectively.
|
||||
|
||||
[NOTE]
|
||||
@ -369,7 +369,7 @@ In fact, both Spring Data JPA and Spring Data Elasticsearch share the same commo
|
||||
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.
|
||||
|
||||
Repositories and documents are found through scanning.
|
||||
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
|
||||
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
|
||||
You can customize the locations to look for repositories and documents by using `@EnableElasticsearchRepositories` and `@EntityScan` respectively.
|
||||
|
||||
TIP: For complete details of Spring Data Elasticsearch, see the {spring-data-elasticsearch-docs}[reference documentation].
|
||||
@ -484,7 +484,7 @@ Spring Data includes basic repository support for Cassandra.
|
||||
Currently, this is more limited than the JPA repositories discussed earlier and needs `@Query` annotated finder methods.
|
||||
|
||||
Repositories and entities are found through scanning.
|
||||
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
|
||||
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
|
||||
You can customize the locations to look for repositories and entities by using `@EnableCassandraRepositories` and `@EntityScan` respectively.
|
||||
|
||||
TIP: For complete details of Spring Data Cassandra, see the https://docs.spring.io/spring-data/cassandra/docs/[reference documentation].
|
||||
@ -538,7 +538,7 @@ To take more control, one or more `ClusterEnvironmentBuilderCustomizer` beans ca
|
||||
Spring Data includes repository support for Couchbase.
|
||||
|
||||
Repositories and documents are found through scanning.
|
||||
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
|
||||
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
|
||||
You can customize the locations to look for repositories and documents by using `@EnableCouchbaseRepositories` and `@EntityScan` respectively.
|
||||
|
||||
For complete details of Spring Data Couchbase, see the {spring-data-couchbase-docs}[reference documentation].
|
||||
@ -608,7 +608,7 @@ Make sure to flag your customized `ContextSource` as `@Primary` so that the auto
|
||||
Spring Data includes repository support for LDAP.
|
||||
|
||||
Repositories and documents are found through scanning.
|
||||
By default, the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) and all those below it are searched.
|
||||
By default, the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
|
||||
You can customize the locations to look for repositories and documents by using `@EnableLdapRepositories` and `@EntityScan` respectively.
|
||||
|
||||
For complete details of Spring Data LDAP, see the https://docs.spring.io/spring-data/ldap/docs/1.0.x/reference/html/[reference documentation].
|
||||
|
@ -206,7 +206,7 @@ You can follow the https://spring.io/guides/gs/accessing-data-jpa/["`Accessing D
|
||||
==== Entity Classes
|
||||
Traditionally, JPA "`Entity`" classes are specified in a `persistence.xml` file.
|
||||
With Spring Boot, this file is not necessary and "`Entity Scanning`" is used instead.
|
||||
By default, all packages below your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) are searched.
|
||||
By default the <<using#using.auto-configuration.packages,auto-configuration packages>> are scanned.
|
||||
|
||||
Any classes annotated with `@Entity`, `@Embeddable`, or `@MappedSuperclass` are considered.
|
||||
A typical entity class resembles the following example:
|
||||
@ -227,7 +227,7 @@ For example, a `CityRepository` interface might declare a `findAllByState(String
|
||||
For more complex queries, you can annotate your method with Spring Data's {spring-data-jpa-api}/repository/Query.html[`Query`] annotation.
|
||||
|
||||
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.
|
||||
If you use auto-configuration, repositories are searched from the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) down.
|
||||
If you use auto-configuration, the <<using#using.auto-configuration.packages,auto-configuration packages>> are searched for repositories.
|
||||
|
||||
TIP: You can customize the locations to look for repositories using `@EnableJpaRepositories`.
|
||||
|
||||
@ -517,7 +517,7 @@ For example, a `CityRepository` interface might declare a `findAllByState(String
|
||||
For more complex queries, you can annotate your method with Spring Data's {spring-data-r2dbc-api}/repository/Query.html[`Query`] annotation.
|
||||
|
||||
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.
|
||||
If you use auto-configuration, repositories are searched from the package containing your main configuration class (the one annotated with `@EnableAutoConfiguration` or `@SpringBootApplication`) down.
|
||||
If you use auto-configuration, the <<using#using.auto-configuration.packages,auto-configuration packages>> are searched for repositories.
|
||||
|
||||
The following example shows a typical Spring Data repository interface definition:
|
||||
|
||||
|
@ -150,14 +150,14 @@ Note that each `configuration` sub namespace provides advanced settings based on
|
||||
[[howto.data-access.spring-data-repositories]]
|
||||
=== Use Spring Data Repositories
|
||||
Spring Data can create implementations of `@Repository` interfaces of various flavors.
|
||||
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.
|
||||
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`.
|
||||
|
||||
For many applications, all you need is to put the right Spring Data dependencies on your classpath.
|
||||
There is a `spring-boot-starter-data-jpa` for JPA, `spring-boot-starter-data-mongodb` for Mongodb, and various other starters for supported technologies.
|
||||
To get started, create some repository interfaces to handle your `@Entity` objects.
|
||||
|
||||
Spring Boot tries to guess the location of your `@Repository` definitions, based on the `@EnableAutoConfiguration` it finds.
|
||||
To get more control, use the `@EnableJpaRepositories` annotation (from Spring Data JPA).
|
||||
Spring Boot determines the location of your `@Repository` definitions by scanning the <<using#using.auto-configuration.packages,auto-configuration packages>>.
|
||||
For more control, use the `@Enable…Repositories` annotations from Spring Data.
|
||||
|
||||
For more about Spring Data, see the {spring-data}[Spring Data project page].
|
||||
|
||||
@ -165,8 +165,8 @@ For more about Spring Data, see the {spring-data}[Spring Data project page].
|
||||
|
||||
[[howto.data-access.separate-entity-definitions-from-spring-configuration]]
|
||||
=== Separate @Entity Definitions from Spring Configuration
|
||||
Spring Boot tries to guess the location of your `@Entity` definitions, based on the `@EnableAutoConfiguration` it finds.
|
||||
To get more control, you can use the `@EntityScan` annotation, as shown in the following example:
|
||||
Spring Boot determines the location of your `@Entity` definitions by scanning the <<using#using.auto-configuration.packages,auto-configuration packages>>.
|
||||
For more control, use the `@EntityScan` annotation, as shown in the following example:
|
||||
|
||||
include::code:MyApplication[]
|
||||
|
||||
|
@ -35,3 +35,10 @@ TIP: You can define exclusions both at the annotation level and by using the pro
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
|
||||
[[using.auto-configuration.packages]]
|
||||
=== Auto-configuration Packages
|
||||
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.
|
||||
The `@EnableAutoConfiguration` annotation (either directly or through its presence on `@SpringBootApplication`) determines the default auto-configuration package.
|
||||
Additional packages can be configured using the `@AutoConfigurationPackage` annotation.
|
||||
|
Loading…
Reference in New Issue
Block a user