Refine spring-boot-docs package restructure

Refine the package restructure started in 91ccc23462 to help provide
a solid foundation for code snippets. This commit renames many of the
classes so that they no longer end in `Example`. It also removes some
of the inner types that were previously used. Many tag comments have
also been moved to ensure that `import` statements are available in
the docs.

Closes gh-25089
This commit is contained in:
Phillip Webb
2021-02-03 11:47:59 -08:00
parent 91ccc23462
commit 2a85427324
63 changed files with 368 additions and 691 deletions

View File

@@ -95,7 +95,7 @@ For instance, the following example loads a YAML configuration file from the cla
[source,java,indent=0]
----
include::{include-howto}/springbootapplication/EnvironmentPostProcessorExample.java[tag=*]
include::{include-howto}/springbootapplication/ExampleEnvironmentPostProcessor.java[tag=*]
----
TIP: The `Environment` has already been prepared with all the usual property sources that Spring Boot loads by default.
@@ -931,7 +931,7 @@ You can add an `org.apache.catalina.connector.Connector` to the `TomcatServletWe
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
include::{include-howto}/embeddedwebservers/TomcatMultipleConnectorsExample.java[tag=*]
include::{include-howto}/embeddedwebservers/TomcatMultipleConnectorsConfiguration.java[tag=*]
----
@@ -951,7 +951,7 @@ To switch to the `LegacyCookieProcessor`, use an `WebServerFactoryCustomizer` be
[source,java,indent=0]
----
include::{include-howto}/embeddedwebservers/TomcatLegacyCookieProcessorExample.java[tag=*]
include::{include-howto}/embeddedwebservers/LegacyCookieProcessorConfiguration.java[tag=*]
----
@@ -978,7 +978,7 @@ Add an `UndertowBuilderCustomizer` to the `UndertowServletWebServerFactory` and
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
include::{include-howto}/embeddedwebservers/UndertowMultipleListenersExample.java[tag=*]
include::{include-howto}/embeddedwebservers/UndertowMultipleListenersConfiguration.java[tag=*]
----
@@ -1283,7 +1283,7 @@ The `jersey.config.server.response.setStatusOverSendError` property must be set
[source,java,indent=0]
----
include::{include-howto}/jersey/JerseySetStatusOverSendErrorExample.java[tag=*]
include::{include-howto}/jersey/JerseySetStatusOverSendErrorConfig.java[tag=*]
----
@@ -1326,7 +1326,7 @@ The following example configures `HttpComponentsClientRequestFactory` with an `H
[source,java,indent=0]
----
include::{include-springbootfeatures}/resttemplate/RestTemplateProxyCustomizationExample.java[tag=*]
include::{include-springbootfeatures}/resttemplate/RestTemplateProxyCustomizer.java[tag=*]
----
[[howto-webclient-reactor-netty-customization]]
@@ -1337,7 +1337,7 @@ The following example configures a 60 second connect timeout and adds a `ReadTim
[source,java,indent=0]
----
include::{include-howto}/httpclients/ReactorNettyClientCustomizationExample.java[tag=*]
include::{include-howto}/httpclients/CustomizeReactorNettyClientConfiguration.java[tag=*]
----
TIP: Note the use of `ReactorResourceFactory` for the connection provider and event loop resources.
@@ -1582,7 +1582,7 @@ The following example shows how to create a data source by using a `DataSourceBu
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
include::{include-howto}/dataaccess/BasicDataSourceExample.java[tag=*]
include::{include-howto}/dataaccess/BasicDataSourceConfiguration.java[tag=*]
----
To run an app with that `DataSource`, all you need is the connection information.
@@ -1623,7 +1623,7 @@ The following example shows how create a `HikariDataSource` with `DataSourceBuil
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
include::{include-howto}/dataaccess/SimpleDataSourceExample.java[tag=*]
include::{include-howto}/dataaccess/SimpleDataSourceConfiguration.java[tag=*]
----
You can even go further by leveraging what `DataSourceProperties` does for you -- that is, by providing a default embedded database with a sensible username and password if no URL is provided.
@@ -1633,7 +1633,7 @@ To avoid that, you can redefine a custom `DataSourceProperties` on your custom n
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
include::{include-howto}/dataaccess/ConfigurableDataSourceExample.java[tag=*]
include::{include-howto}/dataaccess/ConfigurableDataSourceConfiguration.java[tag=*]
----
This setup puts you _in sync_ with what Spring Boot does for you by default, except that a dedicated connection pool is chosen (in code) and its settings are exposed in the `app.datasource.configuration` sub namespace.
@@ -1670,7 +1670,7 @@ In the following example, we provide the _exact_ same feature set as the auto-co
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
include::{include-howto}/dataaccess/SimpleTwoDataSourcesExample.java[tag=*]
include::{include-howto}/dataaccess/SimpleDataSourcesConfiguration.java[tag=*]
----
TIP: `firstDataSourceProperties` has to be flagged as `@Primary` so that the database initializer feature uses your copy (if you use the initializer).
@@ -1700,7 +1700,7 @@ You can apply the same concept to the secondary `DataSource` as well, as shown i
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
include::{include-howto}/dataaccess/CompleteTwoDataSourcesExample.java[tag=*]
include::{include-howto}/dataaccess/CompleteDataSourcesConfiguration.java[tag=*]
----
The preceding example configures two data sources on custom namespaces with the same logic as Spring Boot would use in auto-configuration.
@@ -1794,7 +1794,7 @@ This implementation provides the same table structure as Hibernate 4: all dots a
[source,java,indent=0]
----
include::{include-howto}/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyExample.java[tag=*]
include::{include-howto}/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java[tag=*]
----
If you prefer to use Hibernate 5's default instead, set the following property:
@@ -1828,7 +1828,7 @@ Then, add a `HibernatePropertiesCustomizer` bean as shown in the following examp
[source,java,indent=0]
----
include::{include-howto}/dataaccess/HibernateSecondLevelCacheExample.java[tag=*]
include::{include-howto}/dataaccess/HibernateSecondLevelCacheConfiguration.java[tag=*]
----
This customizer will configure Hibernate to use the same `CacheManager` as the one that the application uses.
@@ -1969,7 +1969,7 @@ For example, if you use Hibernate Search with Elasticsearch as its index manager
[source,java,indent=0]
----
include::{include-howto}/dataaccess/HibernateSearchElasticsearchExample.java[tag=*]
include::{include-howto}/dataaccess/ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java[tag=*]
----
@@ -2066,7 +2066,7 @@ You can initialize the database on startup using SQL scripts as shown in the fol
[source,java,indent=0]
----
include::{include-howto}/dataaccess/R2dbcDatabaseInitializationExample.java[tag=*]
include::{include-howto}/dataaccess/R2dbcDatabaseInitializationConfiguration.java[tag=*]
----
Alternatively, you can configure either <<howto-execute-flyway-database-migrations-on-startup,Flyway>> or <<howto-execute-liquibase-database-migrations-on-startup,Liquibase>> to configure a `DataSource` for you for the duration of the migration.
@@ -2351,7 +2351,7 @@ The following example shows one way to write such an exporter:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
include::{include-howto}/actuator/MetricsHealthMicrometerExportExample.java[tag=*]
include::{include-howto}/actuator/MetricsHealthMicrometerExport.java[tag=*]
----

View File

@@ -2379,7 +2379,7 @@ To register custom metrics, inject `MeterRegistry` into your component, as shown
[source,java,indent=0]
----
include::{include-productionreadyfeatures}/metrics/MetricsMeterRegistryInjectionExample.java[tag=*]
include::{include-productionreadyfeatures}/metrics/MetricsMeterRegistryInjection.java[tag=*]
----
If your metrics depend on other beans, it is recommended that you use a `MeterBinder` to register them, as shown in the following example:
@@ -2404,7 +2404,7 @@ For example, if you want to rename the `mytag.region` tag to `mytag.area` for al
[source,java,indent=0]
----
include::{include-productionreadyfeatures}/metrics/MetricsFilterBeanExample.java[tag=*]
include::{include-productionreadyfeatures}/metrics/MetricsFilterConfiguration.java[tag=*]
----
@@ -2622,7 +2622,7 @@ For Tomcat, the following configuration can be added:
[source,java,indent=0]
----
include::{include-productionreadyfeatures}/cloudfoundry/CloudFoundryCustomContextPathExample.java[tag=*]
include::{include-productionreadyfeatures}/cloudfoundry/CloudFoundryCustomContextPathConfiguration.java[tag=*]
----

View File

@@ -597,7 +597,7 @@ This means that the JSON cannot override properties from lower order property so
[[boot-features-external-config-files]]
=== External Application Properties [[boot-features-external-config-application-property-files]]
=== External Application Properties [[boot-features-external-config-application-property-files]]
Spring Boot will automatically find and load `application.properties` and `application.yaml` files from the following locations when your application starts:
. The classpath root
@@ -1519,7 +1519,7 @@ The properties above will bind to a `Map` with `/key1`, `/key2` and `key3` as th
The slash has been removed from `key3` because it wasn't surrounded by square brackets.
You may also occasionally need to use the bracket notation if your `key` contains a `.` and you are binding to non-scalar value.
For example, binding `a.b=c` to `Map<String, Object>` will return a Map with the entry `{"a"={"b"="c"}}` where as `[a.b]=c` will return a Map with the entry `{"a.b"="c"}`.
For example, binding `a.b=c` to `Map<String, Object>` will return a Map with the entry `{"a"={"b"="c"}}` where as `[a.b]=c` will return a Map with the entry `{"a.b"="c"}`.
@@ -3515,7 +3515,7 @@ The following example shows how to customize `TomcatServletWebServerFactory` tha
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
include::{include-springbootfeatures}/webapplications/TomcatServerCustomizerExample.java[tag=*]
include::{include-springbootfeatures}/webapplications/TomcatServerCustomizer.java[tag=*]
----
@@ -3769,7 +3769,7 @@ For example, you can customize your security configuration by adding something l
[source,java,indent=0]
----
include::{include-springbootfeatures}/security/CustomWebFluxSecurityExample.java[tag=*]
include::{include-springbootfeatures}/security/CustomWebFluxSecurityConfiguration.java[tag=*]
----
@@ -4924,7 +4924,7 @@ To enable transaction management, the following bean must be defined in your con
[source,java,indent=0]
----
include::{include-springbootfeatures}/nosql/Neo4jReactiveTransactionManagerExample.java[tag=*]
include::{include-springbootfeatures}/nosql/Neo4jReactiveTransactionManagerConfiguration.java[tag=*]
----
====
@@ -5609,7 +5609,7 @@ The following example shows a customizer that configures a specific entry expira
[source,java,indent=0]
----
include::{include-springbootfeatures}/nosql/CouchbaseCacheManagerCustomizationExample.java[tag=*]
include::{include-springbootfeatures}/nosql/CouchbaseCacheManagerConfiguration.java[tag=*]
----
@@ -5640,7 +5640,7 @@ The following example shows a customizer that configures a specific time to live
[source,java,indent=0]
----
include::{include-springbootfeatures}/nosql//RedisCacheManagerCustomizationExample.java[tag=*]
include::{include-springbootfeatures}/nosql/RedisCacheManagerConfiguration.java[tag=*]
----
@@ -6208,7 +6208,7 @@ To use the factory bean, wire `StreamsBuilder` into your `@Bean` as shown in the
[source,java,indent=0]
----
include::{include-springbootfeatures}/messaging/KafkaStreamsBeanExample.java[tag=*]
include::{include-springbootfeatures}/messaging/KafkaStreamsConfiguration.java[tag=*]
----
By default, the streams managed by the `StreamBuilder` object it creates are started automatically.
@@ -6363,7 +6363,7 @@ The following example shows a customizer that configures the use of a proxy for
[source,java,indent=0]
----
include::{include-springbootfeatures}/resttemplate/RestTemplateProxyCustomizationExample.java[tag=*]
include::{include-springbootfeatures}/resttemplate/RestTemplateProxyCustomizer.java[tag=*]
----
Finally, you can also create your own `RestTemplateBuilder` bean.
@@ -6372,7 +6372,7 @@ The following example exposes a `RestTemplateBuilder` with what Spring Boot woul
[source,java,indent=0]
----
include::{include-springbootfeatures}/resttemplate/RestTemplateBuilderCustomizationExample.java[tag=*]
include::{include-springbootfeatures}/resttemplate/RestTemplateBuilderConfiguration.java[tag=*]
----
The most extreme (and rarely used) option is to create your own `RestTemplateBuilder` bean without using a configurer.
@@ -7025,7 +7025,7 @@ have `@SpringBootTest` inject them using the `args` attribute.
[source,java,indent=0]
----
include::{include-springbootfeatures}/testing/ApplicationArgumentsExampleTests.java[tag=*]
include::{include-springbootfeatures}/testing/ApplicationArgumentTests.java[tag=*]
----
@@ -7037,7 +7037,7 @@ If you have web endpoints that you want to test against this mock environment, y
[source,java,indent=0]
----
include::{include-springbootfeatures}/testing/MockMvcExampleTests.java[tag=*]
include::{include-springbootfeatures}/testing/MockMvcTests.java[tag=*]
----
TIP: If you want to focus only on the web layer and not start a complete `ApplicationContext`, consider <<boot-features-testing-spring-boot-applications-testing-autoconfigured-mvc-tests,using `@WebMvcTest` instead>>.
@@ -7046,7 +7046,7 @@ Alternatively, you can configure a {spring-framework-docs}/testing.html#webtestc
[source,java,indent=0]
----
include::{include-springbootfeatures}/testing/MockWebTestClientExampleTests.java[tag=*]
include::{include-springbootfeatures}/testing/MockWebTestClientTests.java[tag=*]
----
[TIP]
@@ -7071,7 +7071,7 @@ For convenience, tests that need to make REST calls to the started server can ad
[source,java,indent=0]
----
include::{include-springbootfeatures}/testing/RandomPortWebTestClientExampleTests.java[tag=*]
include::{include-springbootfeatures}/testing/RandomPortWebTestClientTests.java[tag=*]
----
This setup requires `spring-webflux` on the classpath.
@@ -7079,7 +7079,7 @@ If you can't or won't add webflux, Spring Boot also provides a `TestRestTemplate
[source,java,indent=0]
----
include::{include-springbootfeatures}/testing/RandomPortTestRestTemplateExampleTests.java[tag=*]
include::{include-springbootfeatures}/testing/RandomPortTestRestTemplateTests.java[tag=*]
----
@@ -7928,7 +7928,7 @@ If you require more control over Spring REST Docs configuration than offered by
[source,java,indent=0]
----
include::{include-springbootfeatures}/testing/restdocs/webclient/AdvancedConfigurationExample.java[tag=*]
include::{include-springbootfeatures}/testing/restdocs/webclient/AdvancedRestDocsConfiguration.java[tag=*]
----
@@ -7947,7 +7947,7 @@ If you require more control over Spring REST Docs configuration than offered by
[source,java,indent=0]
----
include::{include-springbootfeatures}/testing/restdocs/restassured/AdvancedConfigurationExample.java[tag=*]
include::{include-springbootfeatures}/testing/restdocs/restassured/AdvancedRestDocsConfiguration.java[tag=*]
----