Use convention based code imports

Closes gh-29647
This commit is contained in:
Phillip Webb
2022-02-03 15:01:30 -08:00
parent 71695d2162
commit 0e906dc6e2
57 changed files with 250 additions and 967 deletions

View File

@@ -158,10 +158,7 @@ For example, the following section in `application.properties` shows how you can
=== Using JdbcTemplate
Spring's `JdbcTemplate` and `NamedParameterJdbcTemplate` classes are auto-configured, and you can `@Autowire` them directly into your own beans, as shown in the following example:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/sql/jdbctemplate/MyBean.java[]
----
include::code:MyBean[]
You can customize some properties of the template by using the `spring.jdbc.template.*` properties, as shown in the following example:
@@ -202,10 +199,7 @@ By default, all packages below your main configuration class (the one annotated
Any classes annotated with `@Entity`, `@Embeddable`, or `@MappedSuperclass` are considered.
A typical entity class resembles the following example:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/sql/jpaandspringdata/entityclasses/City.java[]
----
include::code:City[]
TIP: You can customize entity scanning locations by using the `@EntityScan` annotation.
See the "`<<howto#howto.data-access.separate-entity-definitions-from-spring-configuration>>`" how-to.
@@ -225,10 +219,7 @@ If you use auto-configuration, repositories are searched from the package contai
The following example shows a typical Spring Data repository interface definition:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/sql/jpaandspringdata/repositories/CityRepository.java[]
----
include::code:CityRepository[]
Spring Data JPA repositories support three different modes of bootstrapping: default, deferred, and lazy.
To enable deferred or lazy bootstrapping, set the configprop:spring.data.jpa.repositories.bootstrap-mode[] property to `deferred` or `lazy` respectively.
@@ -253,10 +244,7 @@ If {spring-data-envers}[Spring Data Envers] is available, JPA repositories are a
To use Spring Data Envers, make sure your repository extends from `RevisionRepository` as show in the following example:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/sql/jpaandspringdata/enversrepositories/CountryRepository.java[]
----
include::code:CountryRepository[]
NOTE: For more details, check the {spring-data-envers-doc}[Spring Data Envers reference documentation].
@@ -387,19 +375,13 @@ The fluent API offered by jOOQ is initiated through the `org.jooq.DSLContext` in
Spring Boot auto-configures a `DSLContext` as a Spring Bean and connects it to your application `DataSource`.
To use the `DSLContext`, you can inject it, as shown in the following example:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/sql/jooq/dslcontext/MyBean.java[tag=!method]
----
include::code:MyBean[tag=!method]
TIP: The jOOQ manual tends to use a variable named `create` to hold the `DSLContext`.
You can then use the `DSLContext` to construct your queries, as shown in the following example:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/sql/jooq/dslcontext/MyBean.java[tag=method]
----
include::code:MyBean[tag=method]
@@ -449,17 +431,11 @@ TIP: The "`How-to`" section includes a <<howto#howto.data-initialization.using-b
To customize the connections created by a `ConnectionFactory`, that is, set specific parameters that you do not want (or cannot) configure in your central database configuration, you can use a `ConnectionFactoryOptionsBuilderCustomizer` `@Bean`.
The following example shows how to manually override the database port while the rest of the options is taken from the application configuration:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/sql/r2dbc/MyR2dbcConfiguration.java[]
----
include::code:MyR2dbcConfiguration[]
The following examples show how to set some PostgreSQL connection options:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/sql/r2dbc/MyPostgresR2dbcConfiguration.java[]
----
include::code:MyPostgresR2dbcConfiguration[]
When a `ConnectionFactory` bean is available, the regular JDBC `DataSource` auto-configuration backs off.
If you want to retain the JDBC `DataSource` auto-configuration, and are comfortable with the risk of using the blocking JDBC API in a reactive application, add `@Import(DataSourceAutoConfiguration.class)` on a `@Configuration` class in your application to re-enable it.
@@ -493,10 +469,7 @@ If you want to make sure that each context has a separate embedded database, you
==== Using DatabaseClient
A `DatabaseClient` bean is auto-configured, and you can `@Autowire` it directly into your own beans, as shown in the following example:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/sql/r2dbc/usingdatabaseclient/MyBean.java[]
----
include::code:MyBean[]
@@ -513,9 +486,6 @@ If you use auto-configuration, repositories are searched from the package contai
The following example shows a typical Spring Data repository interface definition:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/data/sql/r2dbc/repositories/CityRepository.java[]
----
include::code:CityRepository[]
TIP: We have barely scratched the surface of Spring Data R2DBC. For complete details, see the {spring-data-r2dbc-docs}[Spring Data R2DBC reference documentation].