From 2a85427324803972516416941776c39fb45318fb Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 3 Feb 2021 11:47:59 -0800 Subject: [PATCH] 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 --- .../src/docs/asciidoc/howto.adoc | 34 ++++----- .../asciidoc/production-ready-features.adoc | 6 +- .../docs/asciidoc/spring-boot-features.adoc | 34 ++++----- ...ava => MetricsHealthMicrometerExport.java} | 12 +--- ...java => BasicDataSourceConfiguration.java} | 28 +++----- ...gPhysicalNamingStrategyConfiguration.java} | 14 ++-- ... => CompleteDataSourcesConfiguration.java} | 60 +++++++--------- .../CompleteTwoDataSourcesExample.java | 72 ------------------- .../ConfigurableDataSourceConfiguration.java | 45 ++++++++++++ ...ManagerFactoryDependsOnPostProcessor.java} | 28 +++----- ...bernateSecondLevelCacheConfiguration.java} | 9 +-- ...cDatabaseInitializationConfiguration.java} | 29 +++----- ...ava => SimpleDataSourceConfiguration.java} | 30 +++----- ...va => SimpleDataSourcesConfiguration.java} | 50 ++++++------- ...> LegacyCookieProcessorConfiguration.java} | 28 +++----- ...omcatMultipleConnectorsConfiguration.java} | 11 +-- ...dertowMultipleListenersConfiguration.java} | 27 +++---- ...omizeReactorNettyClientConfiguration.java} | 12 +--- ...> JerseySetStatusOverSendErrorConfig.java} | 35 +++------ ...a => ExampleEnvironmentPostProcessor.java} | 9 +-- ...oundryCustomContextPathConfiguration.java} | 13 ++-- .../endpoints/CustomEndpointExample.java | 5 -- ...e.java => MetricsFilterConfiguration.java} | 23 ++---- ...ava => MetricsMeterRegistryInjection.java} | 39 +++++----- .../SampleMeterBinderConfiguration.java | 17 ++--- .../constructorbinding/AppIoProperties.java | 8 +-- .../javabeanbinding/AppIoProperties.java | 8 +-- .../AppSystemProperties.java | 8 +-- .../javabeanbinding/AppSystemProperties.java | 8 +-- ...le.java => KafkaStreamsConfiguration.java} | 31 +++----- ...> CouchbaseCacheManagerConfiguration.java} | 12 +--- ...ctiveTransactionManagerConfiguration.java} | 12 +--- ...va => RedisCacheManagerConfiguration.java} | 12 +--- ... => RestTemplateBuilderConfiguration.java} | 12 +--- ....java => RestTemplateProxyCustomizer.java} | 49 ++++++------- ...> CustomWebFluxSecurityConfiguration.java} | 26 +++---- .../springapplication/ExitCodeExample.java | 7 +- .../SpringApplicationBuilderExample.java | 11 --- ...sts.java => ApplicationArgumentTests.java} | 4 +- ...MvcExampleTests.java => MockMvcTests.java} | 3 +- ...Tests.java => MockWebTestClientTests.java} | 3 +- .../testing/OutputCaptureTests.java | 7 +- ...a => RandomPortTestRestTemplateTests.java} | 3 +- ...java => RandomPortWebTestClientTests.java} | 3 +- .../UserService.java | 7 +- .../UserServiceAutoConfiguration.java | 9 +-- .../UserServiceAutoConfigurationTests.java | 7 -- .../testing/jmx/SampleApp.java | 6 -- .../testing/jmx/SampleJmxTests.java | 14 ++-- ...ava => AdvancedRestDocsConfiguration.java} | 18 ++--- ...ava => AdvancedRestDocsConfiguration.java} | 18 ++--- .../SampleWebClientConfiguration.java | 6 -- .../webclient/SampleWebClientTests.java | 9 +-- ...ample.java => TomcatServerCustomizer.java} | 12 +--- ...> MetricsHealthMicrometerExportTests.java} | 10 +-- ...=> BasicDataSourceConfigurationTests.java} | 6 +- ...ompleteDataSourcesConfigurationTests.java} | 6 +- ...igurableDataSourceConfigurationTests.java} | 6 +- ...> SimpleDataSourceConfigurationTests.java} | 6 +- ... SimpleDataSourcesConfigurationTests.java} | 6 +- ...acyCookieProcessorConfigurationTests.java} | 8 +-- ...ExampleEnvironmentPostProcessorTests.java} | 6 +- src/checkstyle/checkstyle-suppressions.xml | 2 +- 63 files changed, 368 insertions(+), 691 deletions(-) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/{MetricsHealthMicrometerExportExample.java => MetricsHealthMicrometerExport.java} (85%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/{BasicDataSourceExample.java => BasicDataSourceConfiguration.java} (65%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/{CaseSensitiveSpringPhysicalNamingStrategyExample.java => CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java} (82%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/{SimpleTwoDataSourcesExample.java => CompleteDataSourcesConfiguration.java} (50%) delete mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CompleteTwoDataSourcesExample.java create mode 100644 spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfiguration.java rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/{HibernateSearchElasticsearchExample.java => ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java} (57%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/{HibernateSecondLevelCacheExample.java => HibernateSecondLevelCacheConfiguration.java} (88%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/{R2dbcDatabaseInitializationExample.java => R2dbcDatabaseInitializationConfiguration.java} (62%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/{SimpleDataSourceExample.java => SimpleDataSourceConfiguration.java} (63%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/{ConfigurableDataSourceExample.java => SimpleDataSourcesConfiguration.java} (55%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/{TomcatLegacyCookieProcessorExample.java => LegacyCookieProcessorConfiguration.java} (61%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/{TomcatMultipleConnectorsExample.java => TomcatMultipleConnectorsConfiguration.java} (91%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/{UndertowMultipleListenersExample.java => UndertowMultipleListenersConfiguration.java} (70%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/{ReactorNettyClientCustomizationExample.java => CustomizeReactorNettyClientConfiguration.java} (85%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/{JerseySetStatusOverSendErrorExample.java => JerseySetStatusOverSendErrorConfig.java} (57%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/{EnvironmentPostProcessorExample.java => ExampleEnvironmentPostProcessor.java} (91%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/{CloudFoundryCustomContextPathExample.java => CloudFoundryCustomContextPathConfiguration.java} (92%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/{MetricsFilterBeanExample.java => MetricsFilterConfiguration.java} (68%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/{MetricsMeterRegistryInjectionExample.java => MetricsMeterRegistryInjection.java} (61%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/{KafkaStreamsBeanExample.java => KafkaStreamsConfiguration.java} (66%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/{CouchbaseCacheManagerCustomizationExample.java => CouchbaseCacheManagerConfiguration.java} (85%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/{Neo4jReactiveTransactionManagerExample.java => Neo4jReactiveTransactionManagerConfiguration.java} (82%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/{RedisCacheManagerCustomizationExample.java => RedisCacheManagerConfiguration.java} (85%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/{RestTemplateBuilderCustomizationExample.java => RestTemplateBuilderConfiguration.java} (83%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/{RestTemplateProxyCustomizationExample.java => RestTemplateProxyCustomizer.java} (54%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/{CustomWebFluxSecurityExample.java => CustomWebFluxSecurityConfiguration.java} (72%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/{ApplicationArgumentsExampleTests.java => ApplicationArgumentTests.java} (96%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/{MockMvcExampleTests.java => MockMvcTests.java} (98%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/{MockWebTestClientExampleTests.java => MockWebTestClientTests.java} (97%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/{RandomPortTestRestTemplateExampleTests.java => RandomPortTestRestTemplateTests.java} (96%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/{RandomPortWebTestClientExampleTests.java => RandomPortWebTestClientTests.java} (96%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/{creatingautoconfiguration => testing}/UserService.java (84%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/{creatingautoconfiguration => testing}/UserServiceAutoConfiguration.java (85%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/{AdvancedConfigurationExample.java => AdvancedRestDocsConfiguration.java} (72%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/{AdvancedConfigurationExample.java => AdvancedRestDocsConfiguration.java} (72%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/{TomcatServerCustomizerExample.java => TomcatServerCustomizer.java} (73%) rename spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/actuator/{MetricsHealthMicrometerExportExampleTests.java => MetricsHealthMicrometerExportTests.java} (89%) rename spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/{BasicDataSourceExampleTests.java => BasicDataSourceConfigurationTests.java} (92%) rename spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/{CompleteTwoDataSourcesExampleTests.java => CompleteDataSourcesConfigurationTests.java} (91%) rename spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/{ConfigurableDataSourceExampleTests.java => ConfigurableDataSourceConfigurationTests.java} (91%) rename spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/{SimpleDataSourceExampleTests.java => SimpleDataSourceConfigurationTests.java} (92%) rename spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/{SimpleTwoDataSourcesExampleTests.java => SimpleDataSourcesConfigurationTests.java} (92%) rename spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/{context/embedded/TomcatLegacyCookieProcessorExampleTests.java => howto/embeddedwebservers/LegacyCookieProcessorConfigurationTests.java} (84%) rename spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/springbootapplication/{EnvironmentPostProcessorExampleTests.java => ExampleEnvironmentPostProcessorTests.java} (89%) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc index 948369553b..c53af684b8 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc @@ -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 <> or <> 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=*] ---- diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc index daa3d2e99a..ff93c55db2 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc @@ -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=*] ---- diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc index 5659f9bb9b..8ae7b4e146 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc @@ -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` 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` 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 <>. @@ -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=*] ---- diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExport.java similarity index 85% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExport.java index da10ce4cd9..2813360f47 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExport.java @@ -16,22 +16,16 @@ package org.springframework.boot.docs.howto.actuator; +// tag::code[] import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.MeterRegistry; import org.springframework.boot.actuate.health.HealthEndpoint; -import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.Status; import org.springframework.context.annotation.Configuration; -/** - * Example to show how to export {@link HealthIndicator} beans to a {@link MeterRegistry}. - * - * @author Phillip Webb - */ -public class MetricsHealthMicrometerExportExample { +public class MetricsHealthMicrometerExport { - // tag::code[] @Configuration public class HealthMetricsConfiguration { @@ -55,6 +49,6 @@ public class MetricsHealthMicrometerExportExample { } } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfiguration.java similarity index 65% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfiguration.java index 7ffb6e3873..fd3ca2c6d8 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.howto.dataaccess; +// tag::code[] import javax.sql.DataSource; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -23,27 +24,14 @@ import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for configuring a very basic custom {@link DataSource}. - * - * @author Stephane Nicoll - */ -public class BasicDataSourceExample { - - /** - * A configuration that exposes an empty {@link DataSource}. - */ - @Configuration(proxyBeanMethods = false) - public static class BasicDataSourceConfiguration { - - // tag::code[] - @Bean - @ConfigurationProperties("app.datasource") - public DataSource dataSource() { - return DataSourceBuilder.create().build(); - } - // end::code[] +@Configuration(proxyBeanMethods = false) +public class BasicDataSourceConfiguration { + @Bean + @ConfigurationProperties("app.datasource") + public DataSource dataSource() { + return DataSourceBuilder.create().build(); } } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java similarity index 82% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java index 27e44dd5c1..52f00426e3 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CaseSensitiveSpringPhysicalNamingStrategyConfiguration.java @@ -16,20 +16,16 @@ package org.springframework.boot.docs.howto.dataaccess; +// tag::code[] import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; -/** - * Example configuration for defining a custom {@link SpringPhysicalNamingStrategy} that - * is case sensitive. - * - * @author Andy Wilkinson - */ -class CaseSensitiveSpringPhysicalNamingStrategyExample { +@Configuration +class CaseSensitiveSpringPhysicalNamingStrategyConfiguration { - // tag::code[] @Bean SpringPhysicalNamingStrategy caseSensitivePhysicalNamingStrategy() { return new SpringPhysicalNamingStrategy() { @@ -41,6 +37,6 @@ class CaseSensitiveSpringPhysicalNamingStrategyExample { }; } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleTwoDataSourcesExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfiguration.java similarity index 50% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleTwoDataSourcesExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfiguration.java index 99d6557590..e651b6d2a0 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleTwoDataSourcesExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfiguration.java @@ -16,54 +16,44 @@ package org.springframework.boot.docs.howto.dataaccess; -import javax.sql.DataSource; - +// tag::code[] import com.zaxxer.hikari.HikariDataSource; import org.apache.commons.dbcp2.BasicDataSource; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; -/** - * Example configuration for configuring a configurable secondary {@link DataSource} while - * keeping the auto-configuration defaults for the primary one. - * - * @author Stephane Nicoll - */ -public class SimpleTwoDataSourcesExample { +@Configuration +public class CompleteDataSourcesConfiguration { - /** - * A simple configuration that exposes two data sources. - */ - @Configuration - public static class SimpleDataSourcesConfiguration { + @Bean + @Primary + @ConfigurationProperties("app.datasource.first") + public DataSourceProperties firstDataSourceProperties() { + return new DataSourceProperties(); + } - // tag::code[] - @Bean - @Primary - @ConfigurationProperties("app.datasource.first") - public DataSourceProperties firstDataSourceProperties() { - return new DataSourceProperties(); - } + @Bean + @Primary + @ConfigurationProperties("app.datasource.first.configuration") + public HikariDataSource firstDataSource() { + return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build(); + } - @Bean - @Primary - @ConfigurationProperties("app.datasource.first.configuration") - public HikariDataSource firstDataSource() { - return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build(); - } - - @Bean - @ConfigurationProperties("app.datasource.second") - public BasicDataSource secondDataSource() { - return DataSourceBuilder.create().type(BasicDataSource.class).build(); - } - // end::code[] + @Bean + @ConfigurationProperties("app.datasource.second") + public DataSourceProperties secondDataSourceProperties() { + return new DataSourceProperties(); + } + @Bean + @ConfigurationProperties("app.datasource.second.configuration") + public BasicDataSource secondDataSource() { + return secondDataSourceProperties().initializeDataSourceBuilder().type(BasicDataSource.class).build(); } } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CompleteTwoDataSourcesExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CompleteTwoDataSourcesExample.java deleted file mode 100644 index 824dc54907..0000000000 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/CompleteTwoDataSourcesExample.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.docs.howto.dataaccess; - -import com.zaxxer.hikari.HikariDataSource; -import org.apache.commons.dbcp2.BasicDataSource; - -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -/** - * Example configuration for configuring two data sources with what Spring Boot does in - * auto-configuration. - * - * @author Stephane Nicoll - */ -public class CompleteTwoDataSourcesExample { - - /** - * A complete configuration that exposes two data sources. - */ - @Configuration - public static class CompleteDataSourcesConfiguration { - - // tag::code[] - @Bean - @Primary - @ConfigurationProperties("app.datasource.first") - public DataSourceProperties firstDataSourceProperties() { - return new DataSourceProperties(); - } - - @Bean - @Primary - @ConfigurationProperties("app.datasource.first.configuration") - public HikariDataSource firstDataSource() { - return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build(); - } - - @Bean - @ConfigurationProperties("app.datasource.second") - public DataSourceProperties secondDataSourceProperties() { - return new DataSourceProperties(); - } - - @Bean - @ConfigurationProperties("app.datasource.second.configuration") - public BasicDataSource secondDataSource() { - return secondDataSourceProperties().initializeDataSourceBuilder().type(BasicDataSource.class).build(); - } - // end::code[] - - } - -} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfiguration.java new file mode 100644 index 0000000000..4f0af432f5 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfiguration.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.howto.dataaccess; + +// tag::code[] +import com.zaxxer.hikari.HikariDataSource; + +import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration(proxyBeanMethods = false) +public class ConfigurableDataSourceConfiguration { + + @Bean + @Primary + @ConfigurationProperties("app.datasource") + public DataSourceProperties dataSourceProperties() { + return new DataSourceProperties(); + } + + @Bean + @ConfigurationProperties("app.datasource.configuration") + public HikariDataSource dataSource(DataSourceProperties properties) { + return properties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); + } + +} +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSearchElasticsearchExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java similarity index 57% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSearchElasticsearchExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java index 916a116b6b..737ac85e31 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSearchElasticsearchExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java @@ -16,33 +16,23 @@ package org.springframework.boot.docs.howto.dataaccess; +// tag::code[] import javax.persistence.EntityManagerFactory; import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor; import org.springframework.stereotype.Component; /** - * Example configuration for configuring Hibernate to depend on Elasticsearch so that - * Hibernate Search can use Elasticsearch as its index manager. - * - * @author Andy Wilkinson + * {@link EntityManagerFactoryDependsOnPostProcessor} that ensures that + * {@link EntityManagerFactory} beans depend on the {@code elasticsearchClient} bean. */ -public class HibernateSearchElasticsearchExample { - - // tag::code[] - /** - * {@link EntityManagerFactoryDependsOnPostProcessor} that ensures that - * {@link EntityManagerFactory} beans depend on the {@code elasticsearchClient} bean. - */ - @Component - static class ElasticsearchEntityManagerFactoryDependsOnPostProcessor - extends EntityManagerFactoryDependsOnPostProcessor { - - ElasticsearchEntityManagerFactoryDependsOnPostProcessor() { - super("elasticsearchClient"); - } +@Component +public class ElasticsearchEntityManagerFactoryDependsOnPostProcessor + extends EntityManagerFactoryDependsOnPostProcessor { + ElasticsearchEntityManagerFactoryDependsOnPostProcessor() { + super("elasticsearchClient"); } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSecondLevelCacheExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSecondLevelCacheConfiguration.java similarity index 88% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSecondLevelCacheExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSecondLevelCacheConfiguration.java index b174e7a802..e6fffd5302 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSecondLevelCacheExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/HibernateSecondLevelCacheConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.howto.dataaccess; +// tag::code[] import org.hibernate.cache.jcache.ConfigSettings; import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer; @@ -23,14 +24,8 @@ import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration of using JCache and Hibernate to enable second level caching. - * - * @author Stephane Nicoll - */ -// tag::code[] @Configuration(proxyBeanMethods = false) -public class HibernateSecondLevelCacheExample { +public class HibernateSecondLevelCacheConfiguration { @Bean public HibernatePropertiesCustomizer hibernateSecondLevelCacheCustomizer(JCacheCacheManager cacheManager) { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/R2dbcDatabaseInitializationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/R2dbcDatabaseInitializationConfiguration.java similarity index 62% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/R2dbcDatabaseInitializationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/R2dbcDatabaseInitializationConfiguration.java index 2dfd7b4a42..01625798d3 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/R2dbcDatabaseInitializationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/R2dbcDatabaseInitializationConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.howto.dataaccess; +// tag::code[] import io.r2dbc.spi.ConnectionFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -25,26 +26,16 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.r2dbc.connection.init.ResourceDatabasePopulator; -/** - * Example configuration for initializing a database using R2DBC. - * - * @author Stephane Nicoll - */ -public class R2dbcDatabaseInitializationExample { - - // tag::code[] - @Configuration(proxyBeanMethods = false) - static class DatabaseInitializationConfiguration { - - @Autowired - void initializeDatabase(ConnectionFactory connectionFactory) { - ResourceLoader resourceLoader = new DefaultResourceLoader(); - Resource[] scripts = new Resource[] { resourceLoader.getResource("classpath:schema.sql"), - resourceLoader.getResource("classpath:data.sql") }; - new ResourceDatabasePopulator(scripts).populate(connectionFactory).block(); - } +@Configuration(proxyBeanMethods = false) +public class R2dbcDatabaseInitializationConfiguration { + @Autowired + void initializeDatabase(ConnectionFactory connectionFactory) { + ResourceLoader resourceLoader = new DefaultResourceLoader(); + Resource[] scripts = new Resource[] { resourceLoader.getResource("classpath:schema.sql"), + resourceLoader.getResource("classpath:data.sql") }; + new ResourceDatabasePopulator(scripts).populate(connectionFactory).block(); } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfiguration.java similarity index 63% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfiguration.java index 3c55602513..88df89cf25 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfiguration.java @@ -16,8 +16,7 @@ package org.springframework.boot.docs.howto.dataaccess; -import javax.sql.DataSource; - +// tag::code[] import com.zaxxer.hikari.HikariDataSource; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -25,27 +24,14 @@ import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for configuring a simple {@link DataSource}. - * - * @author Stephane Nicoll - */ -public class SimpleDataSourceExample { - - /** - * A simple configuration that exposes dedicated settings. - */ - @Configuration(proxyBeanMethods = false) - public static class SimpleDataSourceConfiguration { - - // tag::code[] - @Bean - @ConfigurationProperties("app.datasource") - public HikariDataSource dataSource() { - return DataSourceBuilder.create().type(HikariDataSource.class).build(); - } - // end::code[] +@Configuration(proxyBeanMethods = false) +public class SimpleDataSourceConfiguration { + @Bean + @ConfigurationProperties("app.datasource") + public HikariDataSource dataSource() { + return DataSourceBuilder.create().type(HikariDataSource.class).build(); } } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfiguration.java similarity index 55% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfiguration.java index ab38834a4c..434e97a290 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfiguration.java @@ -16,45 +16,39 @@ package org.springframework.boot.docs.howto.dataaccess; -import javax.sql.DataSource; - +// tag::code[] import com.zaxxer.hikari.HikariDataSource; +import org.apache.commons.dbcp2.BasicDataSource; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; -/** - * Example configuration for configuring a configurable custom {@link DataSource}. - * - * @author Stephane Nicoll - */ -public class ConfigurableDataSourceExample { +@Configuration +public class SimpleDataSourcesConfiguration { - /** - * A configuration that defines dedicated settings and reuses - * {@link DataSourceProperties}. - */ - @Configuration(proxyBeanMethods = false) - public static class ConfigurableDataSourceConfiguration { + @Bean + @Primary + @ConfigurationProperties("app.datasource.first") + public DataSourceProperties firstDataSourceProperties() { + return new DataSourceProperties(); + } - // tag::code[] - @Bean - @Primary - @ConfigurationProperties("app.datasource") - public DataSourceProperties dataSourceProperties() { - return new DataSourceProperties(); - } - - @Bean - @ConfigurationProperties("app.datasource.configuration") - public HikariDataSource dataSource(DataSourceProperties properties) { - return properties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); - } - // end::code[] + @Bean + @Primary + @ConfigurationProperties("app.datasource.first.configuration") + public HikariDataSource firstDataSource() { + return firstDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build(); + } + @Bean + @ConfigurationProperties("app.datasource.second") + public BasicDataSource secondDataSource() { + return DataSourceBuilder.create().type(BasicDataSource.class).build(); } } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatLegacyCookieProcessorExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfiguration.java similarity index 61% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatLegacyCookieProcessorExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfiguration.java index 557c4a0b45..4ccb9f6dae 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatLegacyCookieProcessorExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.howto.embeddedwebservers; +// tag::code[] import org.apache.tomcat.util.http.LegacyCookieProcessor; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; @@ -23,27 +24,14 @@ import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for configuring Tomcat with to use {@link LegacyCookieProcessor}. - * - * @author Andy Wilkinson - */ -public class TomcatLegacyCookieProcessorExample { - - /** - * Configuration class that declares the required {@link WebServerFactoryCustomizer}. - */ - @Configuration(proxyBeanMethods = false) - public static class LegacyCookieProcessorConfiguration { - - // tag::code[] - @Bean - public WebServerFactoryCustomizer cookieProcessorCustomizer() { - return (factory) -> factory - .addContextCustomizers((context) -> context.setCookieProcessor(new LegacyCookieProcessor())); - } - // end::code[] +@Configuration(proxyBeanMethods = false) +public class LegacyCookieProcessorConfiguration { + @Bean + public WebServerFactoryCustomizer cookieProcessorCustomizer() { + return (factory) -> factory + .addContextCustomizers((context) -> context.setCookieProcessor(new LegacyCookieProcessor())); } } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatMultipleConnectorsExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatMultipleConnectorsConfiguration.java similarity index 91% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatMultipleConnectorsExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatMultipleConnectorsConfiguration.java index 9608308c8e..62569aeb19 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatMultipleConnectorsExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/TomcatMultipleConnectorsConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.howto.embeddedwebservers; +// tag::code[] import java.io.IOException; import java.net.URL; @@ -28,15 +29,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.util.ResourceUtils; -/** - * Example configuration for configuring Tomcat with an additional {@link Connector}. - * - * @author Stephane Nicoll - */ @Configuration(proxyBeanMethods = false) -public class TomcatMultipleConnectorsExample { +public class TomcatMultipleConnectorsConfiguration { - // tag::code[] @Bean public WebServerFactoryCustomizer sslConnectorCustomizer() { return (tomcat) -> tomcat.addAdditionalTomcatConnectors(createSslConnector()); @@ -63,6 +58,6 @@ public class TomcatMultipleConnectorsExample { throw new IllegalStateException("Fail to create ssl connector", ex); } } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/UndertowMultipleListenersExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/UndertowMultipleListenersConfiguration.java similarity index 70% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/UndertowMultipleListenersExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/UndertowMultipleListenersConfiguration.java index 94f50f4e19..bed31b8b10 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/UndertowMultipleListenersExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/embeddedwebservers/UndertowMultipleListenersConfiguration.java @@ -18,34 +18,23 @@ package org.springframework.boot.docs.howto.embeddedwebservers; import io.undertow.Undertow.Builder; -import org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer; +//tag::code[] import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for configuring Undertow with an additional listener. - * - * @author Stephane Nicoll - */ @Configuration(proxyBeanMethods = false) -public class UndertowMultipleListenersExample { +public class UndertowMultipleListenersConfiguration { - // tag::code[] @Bean public WebServerFactoryCustomizer undertowListenerCustomizer() { - return (factory) -> { - factory.addBuilderCustomizers(new UndertowBuilderCustomizer() { - - @Override - public void customize(Builder builder) { - builder.addHttpListener(8080, "0.0.0.0"); - } - - }); - }; + return (factory) -> factory.addBuilderCustomizers(this::addHttpListener); + } + + private Builder addHttpListener(Builder builder) { + return builder.addHttpListener(8080, "0.0.0.0"); } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/ReactorNettyClientCustomizationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/CustomizeReactorNettyClientConfiguration.java similarity index 85% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/ReactorNettyClientCustomizationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/CustomizeReactorNettyClientConfiguration.java index 6290717ab8..d476add985 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/ReactorNettyClientCustomizationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/httpclients/CustomizeReactorNettyClientConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.howto.httpclients; +// tag::code[] import io.netty.channel.ChannelOption; import io.netty.handler.timeout.ReadTimeoutHandler; import reactor.netty.http.client.HttpClient; @@ -25,17 +26,10 @@ import org.springframework.context.annotation.Configuration; import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.http.client.reactive.ReactorResourceFactory; -import org.springframework.web.reactive.function.client.WebClient; -/** - * Example configuration for customizing the Reactor Netty-based {@link WebClient}. - * - * @author Andy Wilkinson - */ @Configuration(proxyBeanMethods = false) -public class ReactorNettyClientCustomizationExample { +public class CustomizeReactorNettyClientConfiguration { - // tag::code[] @Bean ClientHttpConnector clientHttpConnector(ReactorResourceFactory resourceFactory) { HttpClient httpClient = HttpClient.create(resourceFactory.getConnectionProvider()) @@ -43,6 +37,6 @@ public class ReactorNettyClientCustomizationExample { .doOnConnected((connection) -> connection.addHandlerLast(new ReadTimeoutHandler(60))); return new ReactorClientHttpConnector(httpClient); } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/JerseySetStatusOverSendErrorExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/JerseySetStatusOverSendErrorConfig.java similarity index 57% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/JerseySetStatusOverSendErrorExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/JerseySetStatusOverSendErrorConfig.java index 6720bd3b91..52a5be8ab5 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/JerseySetStatusOverSendErrorExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/jersey/JerseySetStatusOverSendErrorConfig.java @@ -16,37 +16,24 @@ package org.springframework.boot.docs.howto.jersey; +// tag::code[] import java.util.Collections; -import javax.servlet.http.HttpServletResponse; - import org.glassfish.jersey.server.ResourceConfig; import org.springframework.stereotype.Component; -/** - * Example configuration for a Jersey {@link ResourceConfig} configured to use - * {@link HttpServletResponse#setStatus(int)} rather than - * {@link HttpServletResponse#sendError(int)}. - * - * @author Andy Wilkinson - */ -public class JerseySetStatusOverSendErrorExample { - - // tag::code[] - @Component - public class JerseyConfig extends ResourceConfig { - - public JerseyConfig() { - register(Endpoint.class); - setProperties(Collections.singletonMap("jersey.config.server.response.setStatusOverSendError", true)); - } - - } - // end::code[] - - static class Endpoint { +@Component +public class JerseySetStatusOverSendErrorConfig extends ResourceConfig { + public JerseySetStatusOverSendErrorConfig() { + register(Endpoint.class); + setProperties(Collections.singletonMap("jersey.config.server.response.setStatusOverSendError", true)); } } +// end::code[] + +class Endpoint { + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/EnvironmentPostProcessorExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/ExampleEnvironmentPostProcessor.java similarity index 91% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/EnvironmentPostProcessorExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/ExampleEnvironmentPostProcessor.java index 3b7a90b764..33c9ca51ea 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/EnvironmentPostProcessorExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/springbootapplication/ExampleEnvironmentPostProcessor.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.howto.springbootapplication; +// tag::code[] import java.io.IOException; import org.springframework.boot.SpringApplication; @@ -27,13 +28,7 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.util.Assert; -/** - * An {@link EnvironmentPostProcessor} example that loads a YAML file. - * - * @author Stephane Nicoll - */ -// tag::code[] -public class EnvironmentPostProcessorExample implements EnvironmentPostProcessor { +public class ExampleEnvironmentPostProcessor implements EnvironmentPostProcessor { private final YamlPropertySourceLoader loader = new YamlPropertySourceLoader(); diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/CloudFoundryCustomContextPathExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/CloudFoundryCustomContextPathConfiguration.java similarity index 92% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/CloudFoundryCustomContextPathExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/CloudFoundryCustomContextPathConfiguration.java index f9d6fcd7eb..7264c032db 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/CloudFoundryCustomContextPathExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/cloudfoundry/CloudFoundryCustomContextPathConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.productionreadyfeatures.cloudfoundry; +// tag::code[] import java.io.IOException; import java.util.Collections; @@ -36,15 +37,9 @@ import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for custom context path in Cloud Foundry. - * - * @author Johnny Lim - */ @Configuration(proxyBeanMethods = false) -public class CloudFoundryCustomContextPathExample { +public class CloudFoundryCustomContextPathConfiguration { - // tag::code[] @Bean public TomcatServletWebServerFactory servletWebServerFactory() { return new TomcatServletWebServerFactory() { @@ -65,7 +60,7 @@ public class CloudFoundryCustomContextPathExample { } private ServletContainerInitializer getServletContextInitializer(String contextPath) { - return (c, context) -> { + return (classes, context) -> { Servlet servlet = new GenericServlet() { @Override @@ -78,6 +73,6 @@ public class CloudFoundryCustomContextPathExample { context.addServlet("cloudfoundry", servlet).addMapping("/*"); }; } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/endpoints/CustomEndpointExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/endpoints/CustomEndpointExample.java index a46938dd30..cb8135af13 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/endpoints/CustomEndpointExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/endpoints/CustomEndpointExample.java @@ -20,11 +20,6 @@ import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; -/** - * An example of a custom actuator endpoint. - * - * @author Stephane Nicoll - */ @Endpoint(id = "custom") public class CustomEndpointExample { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsFilterBeanExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsFilterConfiguration.java similarity index 68% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsFilterBeanExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsFilterConfiguration.java index 103ff1311e..b1d6e6335d 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsFilterBeanExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsFilterConfiguration.java @@ -16,28 +16,19 @@ package org.springframework.boot.docs.productionreadyfeatures.metrics; +// tag::code[] import io.micrometer.core.instrument.config.MeterFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example to show a {@link MeterFilter}. - * - * @author Phillip Webb - */ -public class MetricsFilterBeanExample { - - @Configuration(proxyBeanMethods = false) - public static class MetricsFilterExampleConfiguration { - - // tag::code[] - @Bean - public MeterFilter renameRegionTagMeterFilter() { - return MeterFilter.renameTag("com.example", "mytag.region", "mytag.area"); - } - // end::code[] +@Configuration(proxyBeanMethods = false) +public class MetricsFilterConfiguration { + @Bean + public MeterFilter renameRegionTagMeterFilter() { + return MeterFilter.renameTag("com.example", "mytag.region", "mytag.area"); } } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsMeterRegistryInjectionExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsMeterRegistryInjection.java similarity index 61% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsMeterRegistryInjectionExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsMeterRegistryInjection.java index 3845936b0e..093a7edac8 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsMeterRegistryInjectionExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/MetricsMeterRegistryInjection.java @@ -16,31 +16,36 @@ package org.springframework.boot.docs.productionreadyfeatures.metrics; +//tag::code[] +import java.util.Collections; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; -/** - * Example to show injection and use of a {@link MeterRegistry}. - * - * @author Andy Wilkinson - */ -public class MetricsMeterRegistryInjectionExample { +import org.springframework.stereotype.Component; - // tag::code[] - class Dictionary { +@Component +public class MetricsMeterRegistryInjection { - private final List words = new CopyOnWriteArrayList<>(); - - Dictionary(MeterRegistry registry) { - registry.gaugeCollectionSize("dictionary.size", Tags.empty(), this.words); - } - - // ... + private final Dictionary dictionary; + MetricsMeterRegistryInjection(MeterRegistry registry) { + this.dictionary = Dictionary.load(); + registry.gauge("dictionary.size", Tags.empty(), this.dictionary.getWords().size()); + } + +} +// end::code[] + +class Dictionary { + + static Dictionary load() { + return new Dictionary(); + } + + List getWords() { + return Collections.emptyList(); } - // end::code[] } diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/SampleMeterBinderConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/SampleMeterBinderConfiguration.java index b289ab58cf..18d28419d9 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/SampleMeterBinderConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/SampleMeterBinderConfiguration.java @@ -16,31 +16,26 @@ package org.springframework.boot.docs.productionreadyfeatures.metrics; +// tag::code[] import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.binder.MeterBinder; import org.springframework.context.annotation.Bean; -/** - * Example to show configuration of a custom {@link MeterBinder}. - * - * @author Andy Wilkinson - */ public class SampleMeterBinderConfiguration { - // tag::code[] @Bean MeterBinder queueSize(Queue queue) { return (registry) -> Gauge.builder("queueSize", queue::size).register(registry); } - // end::code[] - static class Queue { +} +// end::code[] - int size() { - return 5; - } +class Queue { + int size() { + return 5; } } diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/constructorbinding/AppIoProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/constructorbinding/AppIoProperties.java index b94754e06a..ea1b16249e 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/constructorbinding/AppIoProperties.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/constructorbinding/AppIoProperties.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.datasize.constructorbinding; +// tag::code[] import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.boot.context.properties.bind.DefaultValue; @@ -23,13 +24,6 @@ import org.springframework.boot.convert.DataSizeUnit; import org.springframework.util.unit.DataSize; import org.springframework.util.unit.DataUnit; -/** - * A {@link ConfigurationProperties @ConfigurationProperties} example that uses - * {@link DataSize}. - * - * @author Stephane Nicoll - */ -// tag::code[] @ConfigurationProperties("app.io") @ConstructorBinding public class AppIoProperties { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/javabeanbinding/AppIoProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/javabeanbinding/AppIoProperties.java index 7aba686820..c69b097d70 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/javabeanbinding/AppIoProperties.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/datasize/javabeanbinding/AppIoProperties.java @@ -16,18 +16,12 @@ package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.datasize.javabeanbinding; +// tag::code[] import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.convert.DataSizeUnit; import org.springframework.util.unit.DataSize; import org.springframework.util.unit.DataUnit; -/** - * A {@link ConfigurationProperties @ConfigurationProperties} example that uses - * {@link DataSize}. - * - * @author Stephane Nicoll - */ -// tag::code[] @ConfigurationProperties("app.io") public class AppIoProperties { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/constructorbinding/AppSystemProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/constructorbinding/AppSystemProperties.java index 58089d7bb6..bdfb5a3bb6 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/constructorbinding/AppSystemProperties.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/constructorbinding/AppSystemProperties.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.duration.constructorbinding; +// tag::code[] import java.time.Duration; import java.time.temporal.ChronoUnit; @@ -24,13 +25,6 @@ import org.springframework.boot.context.properties.ConstructorBinding; import org.springframework.boot.context.properties.bind.DefaultValue; import org.springframework.boot.convert.DurationUnit; -/** - * A {@link ConfigurationProperties @ConfigurationProperties} example that uses - * {@link Duration}. - * - * @author Stephane Nicoll - */ -// tag::code[] @ConfigurationProperties("app.system") @ConstructorBinding public class AppSystemProperties { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/javabeanbinding/AppSystemProperties.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/javabeanbinding/AppSystemProperties.java index 5ee4ef56ce..9aabcd46ec 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/javabeanbinding/AppSystemProperties.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/externalizedconfiguration/duration/javabeanbinding/AppSystemProperties.java @@ -16,19 +16,13 @@ package org.springframework.boot.docs.springbootfeatures.externalizedconfiguration.duration.javabeanbinding; +// tag::code[] import java.time.Duration; import java.time.temporal.ChronoUnit; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.convert.DurationUnit; -/** - * A {@link ConfigurationProperties @ConfigurationProperties} example that uses - * {@link Duration}. - * - * @author Stephane Nicoll - */ -// tag::code[] @ConfigurationProperties("app.system") public class AppSystemProperties { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/KafkaStreamsBeanExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/KafkaStreamsConfiguration.java similarity index 66% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/KafkaStreamsBeanExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/KafkaStreamsConfiguration.java index 7575be40f3..2a4dbdd305 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/KafkaStreamsBeanExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/messaging/KafkaStreamsConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.springbootfeatures.messaging; +// tag::code[] import org.apache.kafka.common.serialization.Serdes; import org.apache.kafka.streams.KeyValue; import org.apache.kafka.streams.StreamsBuilder; @@ -27,27 +28,17 @@ import org.springframework.context.annotation.Configuration; import org.springframework.kafka.annotation.EnableKafkaStreams; import org.springframework.kafka.support.serializer.JsonSerde; -/** - * Example to show usage of {@link StreamsBuilder}. - * - * @author Stephane Nicoll - */ -public class KafkaStreamsBeanExample { - - // tag::code[] - @Configuration(proxyBeanMethods = false) - @EnableKafkaStreams - public static class KafkaStreamsExampleConfiguration { - - @Bean - public KStream kStream(StreamsBuilder streamsBuilder) { - KStream stream = streamsBuilder.stream("ks1In"); - stream.map((k, v) -> new KeyValue<>(k, v.toUpperCase())).to("ks1Out", - Produced.with(Serdes.Integer(), new JsonSerde<>())); - return stream; - } +@Configuration(proxyBeanMethods = false) +@EnableKafkaStreams +public class KafkaStreamsConfiguration { + @Bean + public KStream kStream(StreamsBuilder streamsBuilder) { + KStream stream = streamsBuilder.stream("ks1In"); + stream.map((k, v) -> new KeyValue<>(k, v.toUpperCase())).to("ks1Out", + Produced.with(Serdes.Integer(), new JsonSerde<>())); + return stream; } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/CouchbaseCacheManagerCustomizationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/CouchbaseCacheManagerConfiguration.java similarity index 85% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/CouchbaseCacheManagerCustomizationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/CouchbaseCacheManagerConfiguration.java index 987c877946..e130e09ce4 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/CouchbaseCacheManagerCustomizationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/CouchbaseCacheManagerConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.springbootfeatures.nosql; +// tag::code[] import java.time.Duration; import org.springframework.boot.autoconfigure.cache.CouchbaseCacheManagerBuilderCustomizer; @@ -23,16 +24,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.couchbase.cache.CouchbaseCacheConfiguration; -/** - * An example how to customize {@code CouchbaseCacheManagerBuilder} via - * {@code CouchbaseCacheManagerBuilderCustomizer}. - * - * @author Dmytro Nosan - */ @Configuration(proxyBeanMethods = false) -public class CouchbaseCacheManagerCustomizationExample { +public class CouchbaseCacheManagerConfiguration { - // tag::code[] @Bean public CouchbaseCacheManagerBuilderCustomizer myCouchbaseCacheManagerBuilderCustomizer() { return (builder) -> builder @@ -42,6 +36,6 @@ public class CouchbaseCacheManagerCustomizationExample { CouchbaseCacheConfiguration.defaultCacheConfig().entryExpiry(Duration.ofMinutes(1))); } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/Neo4jReactiveTransactionManagerExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/Neo4jReactiveTransactionManagerConfiguration.java similarity index 82% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/Neo4jReactiveTransactionManagerExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/Neo4jReactiveTransactionManagerConfiguration.java index 24398a43f0..34ef8f4f5e 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/Neo4jReactiveTransactionManagerExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/Neo4jReactiveTransactionManagerConfiguration.java @@ -16,28 +16,22 @@ package org.springframework.boot.docs.springbootfeatures.nosql; +// tag::code[] import org.neo4j.driver.Driver; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.neo4j.core.ReactiveDatabaseSelectionProvider; import org.springframework.data.neo4j.core.transaction.ReactiveNeo4jTransactionManager; -import org.springframework.transaction.ReactiveTransactionManager; -/** - * Example to show user-defined registration of a {@link ReactiveTransactionManager}. - * - * @author Stephane Nicoll - */ @Configuration(proxyBeanMethods = false) -public class Neo4jReactiveTransactionManagerExample { +public class Neo4jReactiveTransactionManagerConfiguration { - // tag::code[] @Bean public ReactiveNeo4jTransactionManager reactiveTransactionManager(Driver driver, ReactiveDatabaseSelectionProvider databaseNameProvider) { return new ReactiveNeo4jTransactionManager(driver, databaseNameProvider); } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/RedisCacheManagerCustomizationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/RedisCacheManagerConfiguration.java similarity index 85% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/RedisCacheManagerCustomizationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/RedisCacheManagerConfiguration.java index fef562a29d..d3b0b97804 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/RedisCacheManagerCustomizationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/nosql/RedisCacheManagerConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.springbootfeatures.nosql; +// tag::code[] import java.time.Duration; import org.springframework.boot.autoconfigure.cache.RedisCacheManagerBuilderCustomizer; @@ -23,16 +24,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.cache.RedisCacheConfiguration; -/** - * An example how to customize {@code RedisCacheManagerBuilder} via - * {@code RedisCacheManagerBuilderCustomizer}. - * - * @author Dmytro Nosan - */ @Configuration(proxyBeanMethods = false) -public class RedisCacheManagerCustomizationExample { +public class RedisCacheManagerConfiguration { - // tag::code[] @Bean public RedisCacheManagerBuilderCustomizer myRedisCacheManagerBuilderCustomizer() { return (builder) -> builder @@ -42,6 +36,6 @@ public class RedisCacheManagerCustomizationExample { RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofMinutes(1))); } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateBuilderCustomizationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateBuilderConfiguration.java similarity index 83% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateBuilderCustomizationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateBuilderConfiguration.java index 41f641abee..7ad9628e7f 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateBuilderCustomizationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateBuilderConfiguration.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.springbootfeatures.resttemplate; +// tag::code[] import java.time.Duration; import org.springframework.boot.autoconfigure.web.client.RestTemplateBuilderConfigurer; @@ -23,21 +24,14 @@ import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Example configuration for using a {@link RestTemplateBuilderConfigurer} to configure a - * custom {@link RestTemplateBuilder}. - * - * @author Stephane Nicoll - */ @Configuration(proxyBeanMethods = false) -public class RestTemplateBuilderCustomizationExample { +public class RestTemplateBuilderConfiguration { - // tag::code[] @Bean public RestTemplateBuilder restTemplateBuilder(RestTemplateBuilderConfigurer configurer) { return configurer.configure(new RestTemplateBuilder()).setConnectTimeout(Duration.ofSeconds(5)) .setReadTimeout(Duration.ofSeconds(2)); } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateProxyCustomizationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateProxyCustomizer.java similarity index 54% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateProxyCustomizationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateProxyCustomizer.java index 4fb1170fd2..37a06cb232 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateProxyCustomizationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/resttemplate/RestTemplateProxyCustomizer.java @@ -16,10 +16,12 @@ package org.springframework.boot.docs.springbootfeatures.resttemplate; +// tag::code[] import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.client.HttpClient; +import org.apache.http.conn.routing.HttpRoutePlanner; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.DefaultProxyRoutePlanner; import org.apache.http.protocol.HttpContext; @@ -28,39 +30,30 @@ import org.springframework.boot.web.client.RestTemplateCustomizer; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; -/** - * Example configuration for using a {@link RestTemplateCustomizer} to configure a proxy. - * - * @author Andy Wilkinson - */ -public class RestTemplateProxyCustomizationExample { +public class RestTemplateProxyCustomizer implements RestTemplateCustomizer { - /** - * A {@link RestTemplateCustomizer} that applies an HttpComponents-based request - * factory that is configured to use a proxy. - */ - // tag::code[] - static class ProxyCustomizer implements RestTemplateCustomizer { + @Override + public void customize(RestTemplate restTemplate) { + HttpRoutePlanner routePlanner = new CustomRoutePlanner(new HttpHost("proxy.example.com")); + HttpClient httpClient = HttpClientBuilder.create().setRoutePlanner(routePlanner).build(); + restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); + } + + static class CustomRoutePlanner extends DefaultProxyRoutePlanner { + + CustomRoutePlanner(HttpHost proxy) { + super(proxy); + } @Override - public void customize(RestTemplate restTemplate) { - HttpHost proxy = new HttpHost("proxy.example.com"); - HttpClient httpClient = HttpClientBuilder.create().setRoutePlanner(new DefaultProxyRoutePlanner(proxy) { - - @Override - public HttpHost determineProxy(HttpHost target, HttpRequest request, HttpContext context) - throws HttpException { - if (target.getHostName().equals("192.168.0.5")) { - return null; - } - return super.determineProxy(target, request, context); - } - - }).build(); - restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); + public HttpHost determineProxy(HttpHost target, HttpRequest request, HttpContext context) throws HttpException { + if (target.getHostName().equals("192.168.0.5")) { + return null; + } + return super.determineProxy(target, request, context); } } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/CustomWebFluxSecurityExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/CustomWebFluxSecurityConfiguration.java similarity index 72% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/CustomWebFluxSecurityExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/CustomWebFluxSecurityConfiguration.java index e82d72250a..219e8feb90 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/CustomWebFluxSecurityExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/security/CustomWebFluxSecurityConfiguration.java @@ -16,33 +16,25 @@ package org.springframework.boot.docs.springbootfeatures.security; +// tag::code[] import org.springframework.boot.autoconfigure.security.reactive.PathRequest; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.web.server.SecurityWebFilterChain; -/** - * Example configuration for customizing security rules for a WebFlux application. - * - * @author Madhura Bhave - */ @Configuration(proxyBeanMethods = false) -public class CustomWebFluxSecurityExample { +public class CustomWebFluxSecurityConfiguration { - // @formatter:off - // tag::code[] @Bean public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { - return http - .authorizeExchange() - .matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() - .pathMatchers("/foo", "/bar") - .authenticated().and() - .formLogin().and() - .build(); + http.authorizeExchange((spec) -> { + spec.matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll(); + spec.pathMatchers("/foo", "/bar").authenticated(); + }); + http.formLogin(); + return http.build(); } - // end::code[] - // @formatter:on } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/ExitCodeExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/ExitCodeExample.java index 43c81fd2ec..ea8514b38f 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/ExitCodeExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/ExitCodeExample.java @@ -16,17 +16,12 @@ package org.springframework.boot.docs.springbootfeatures.springapplication; +// tag::code[] import org.springframework.boot.ExitCodeGenerator; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -/** - * Example configuration that illustrates the use of {@link ExitCodeGenerator}. - * - * @author Stephane Nicoll - */ -// tag::code[] @SpringBootApplication public class ExitCodeExample { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/SpringApplicationBuilderExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/SpringApplicationBuilderExample.java index 9d2225a996..84220a9144 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/SpringApplicationBuilderExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/springapplication/SpringApplicationBuilderExample.java @@ -19,11 +19,6 @@ package org.springframework.boot.docs.springbootfeatures.springapplication; import org.springframework.boot.Banner; import org.springframework.boot.builder.SpringApplicationBuilder; -/** - * Examples of using {@link SpringApplicationBuilder}. - * - * @author Andy Wilkinson - */ public class SpringApplicationBuilderExample { public void hierarchyWithDisabledBanner(String[] args) { @@ -38,16 +33,10 @@ public class SpringApplicationBuilderExample { // @formatter:on } - /** - * Parent application configuration. - */ static class Parent { } - /** - * Application configuration. - */ static class Application { } diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/ApplicationArgumentsExampleTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/ApplicationArgumentTests.java similarity index 96% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/ApplicationArgumentsExampleTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/ApplicationArgumentTests.java index 5e309044c8..620cbad89e 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/ApplicationArgumentsExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/ApplicationArgumentTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.springbootfeatures.testing; +// tag::code[] import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -24,9 +25,8 @@ import org.springframework.boot.test.context.SpringBootTest; import static org.assertj.core.api.Assertions.assertThat; -// tag::code[] @SpringBootTest(args = "--app.test=one") -class ApplicationArgumentsExampleTests { +class ApplicationArgumentTests { @Test void applicationArgumentsPopulated(@Autowired ApplicationArguments args) { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockMvcExampleTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockMvcTests.java similarity index 98% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockMvcExampleTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockMvcTests.java index a660a8d3d1..513a85336d 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockMvcExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockMvcTests.java @@ -17,7 +17,6 @@ package org.springframework.boot.docs.springbootfeatures.testing; // tag::code[] - import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -31,7 +30,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @SpringBootTest @AutoConfigureMockMvc -class MockMvcExampleTests { +class MockMvcTests { @Test void exampleTest(@Autowired MockMvc mvc) throws Exception { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockWebTestClientExampleTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockWebTestClientTests.java similarity index 97% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockWebTestClientExampleTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockWebTestClientTests.java index f747b1b144..4a1ae58c0f 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockWebTestClientExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/MockWebTestClientTests.java @@ -17,7 +17,6 @@ package org.springframework.boot.docs.springbootfeatures.testing; // tag::code[] - import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -27,7 +26,7 @@ import org.springframework.test.web.reactive.server.WebTestClient; @SpringBootTest @AutoConfigureWebTestClient -class MockWebTestClientExampleTests { +class MockWebTestClientTests { @Test void exampleTest(@Autowired WebTestClient webClient) { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/OutputCaptureTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/OutputCaptureTests.java index 8be3578e25..bd5989d9a4 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/OutputCaptureTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/OutputCaptureTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.springbootfeatures.testing; +// tag::code[] import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -24,12 +25,6 @@ import org.springframework.boot.test.system.OutputCaptureExtension; import static org.assertj.core.api.Assertions.assertThat; -/** - * Sample showcasing the use of {@link CapturedOutput}. - * - * @author Stephane Nicoll - */ -// tag::code[] @ExtendWith(OutputCaptureExtension.class) class OutputCaptureTests { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortTestRestTemplateExampleTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortTestRestTemplateTests.java similarity index 96% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortTestRestTemplateExampleTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortTestRestTemplateTests.java index 4eec421c87..3ba15b7e1d 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortTestRestTemplateExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortTestRestTemplateTests.java @@ -17,7 +17,6 @@ package org.springframework.boot.docs.springbootfeatures.testing; // tag::code[] - import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -28,7 +27,7 @@ import org.springframework.boot.test.web.client.TestRestTemplate; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class RandomPortTestRestTemplateExampleTests { +class RandomPortTestRestTemplateTests { @Test void exampleTest(@Autowired TestRestTemplate restTemplate) { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortWebTestClientExampleTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortWebTestClientTests.java similarity index 96% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortWebTestClientExampleTests.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortWebTestClientTests.java index 7274832489..60ff61d2ef 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortWebTestClientExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/RandomPortWebTestClientTests.java @@ -17,7 +17,6 @@ package org.springframework.boot.docs.springbootfeatures.testing; // tag::code[] - import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -26,7 +25,7 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.test.web.reactive.server.WebTestClient; @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -class RandomPortWebTestClientExampleTests { +class RandomPortWebTestClientTests { @Test void exampleTest(@Autowired WebTestClient webClient) { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/UserService.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserService.java similarity index 84% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/UserService.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserService.java index 028fe37b5f..edc4e8363c 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/UserService.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserService.java @@ -14,13 +14,8 @@ * limitations under the License. */ -package org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration; +package org.springframework.boot.docs.springbootfeatures.testing; -/** - * Sample service. - * - * @author Stephane Nicoll - */ public class UserService { private final String name; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/UserServiceAutoConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfiguration.java similarity index 85% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/UserServiceAutoConfiguration.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfiguration.java index 6b902d778b..e844120284 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/creatingautoconfiguration/UserServiceAutoConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfiguration.java @@ -14,21 +14,16 @@ * limitations under the License. */ -package org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration; +package org.springframework.boot.docs.springbootfeatures.testing; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration.UserServiceAutoConfiguration.UserProperties; +import org.springframework.boot.docs.springbootfeatures.testing.UserServiceAutoConfiguration.UserProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -/** - * Sample auto-configuration. - * - * @author Stephane Nicoll - */ @Configuration(proxyBeanMethods = false) @ConditionalOnClass(UserService.class) @EnableConfigurationProperties(UserProperties.class) diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfigurationTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfigurationTests.java index 1ab6c8903a..3250a45467 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/UserServiceAutoConfigurationTests.java @@ -19,8 +19,6 @@ package org.springframework.boot.docs.springbootfeatures.testing; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration.UserService; -import org.springframework.boot.docs.springbootfeatures.creatingautoconfiguration.UserServiceAutoConfiguration; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; @@ -28,11 +26,6 @@ import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; -/** - * Tests for {@link UserServiceAutoConfiguration}. - * - * @author Stephane Nicoll - */ class UserServiceAutoConfigurationTests { // tag::runner[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleApp.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleApp.java index 71efc7caab..0edc242b2f 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleApp.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleApp.java @@ -20,12 +20,6 @@ import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; -/** - * A sample {@link SpringBootConfiguration @ConfigurationProperties} that only enables JMX - * auto-configuration. - * - * @author Stephane Nicoll - */ @SpringBootConfiguration @ImportAutoConfiguration(JmxAutoConfiguration.class) public class SampleApp { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleJmxTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleJmxTests.java index eefe5b29a6..74e695e397 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleJmxTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/jmx/SampleJmxTests.java @@ -16,7 +16,9 @@ package org.springframework.boot.docs.springbootfeatures.testing.jmx; +// tag::code[] import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -26,13 +28,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringExtension; -/** - * Example integration test that uses JMX. - * - * @author Stephane Nicoll - */ -@SuppressWarnings("unused") -// tag::code[] +import static org.assertj.core.api.Assertions.assertThat; + @ExtendWith(SpringExtension.class) @SpringBootTest(properties = "spring.jmx.enabled=true") @DirtiesContext @@ -42,7 +39,8 @@ class SampleJmxTests { private MBeanServer mBeanServer; @Test - void exampleTest() { + void exampleTest() throws MalformedObjectNameException { + assertThat(this.mBeanServer.getDomains()).contains("java.lang"); // ... } diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/AdvancedConfigurationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/AdvancedRestDocsConfiguration.java similarity index 72% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/AdvancedConfigurationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/AdvancedRestDocsConfiguration.java index f1ffafff00..11bd105906 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/AdvancedConfigurationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/restassured/AdvancedRestDocsConfiguration.java @@ -16,23 +16,19 @@ package org.springframework.boot.docs.springbootfeatures.testing.restdocs.restassured; +// tag::code[] import org.springframework.boot.test.autoconfigure.restdocs.RestDocsRestAssuredConfigurationCustomizer; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.restdocs.restassured3.RestAssuredRestDocumentationConfigurer; import org.springframework.restdocs.templates.TemplateFormats; -public class AdvancedConfigurationExample { - - // tag::code[] - @TestConfiguration(proxyBeanMethods = false) - public static class CustomizationConfiguration implements RestDocsRestAssuredConfigurationCustomizer { - - @Override - public void customize(RestAssuredRestDocumentationConfigurer configurer) { - configurer.snippets().withTemplateFormat(TemplateFormats.markdown()); - } +@TestConfiguration(proxyBeanMethods = false) +public class AdvancedRestDocsConfiguration implements RestDocsRestAssuredConfigurationCustomizer { + @Override + public void customize(RestAssuredRestDocumentationConfigurer configurer) { + configurer.snippets().withTemplateFormat(TemplateFormats.markdown()); } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/AdvancedConfigurationExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/AdvancedRestDocsConfiguration.java similarity index 72% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/AdvancedConfigurationExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/AdvancedRestDocsConfiguration.java index bd38c93b33..16ca58f246 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/AdvancedConfigurationExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/restdocs/webclient/AdvancedRestDocsConfiguration.java @@ -16,22 +16,18 @@ package org.springframework.boot.docs.springbootfeatures.testing.restdocs.webclient; +// tag::code[] import org.springframework.boot.test.autoconfigure.restdocs.RestDocsWebTestClientConfigurationCustomizer; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentationConfigurer; -public class AdvancedConfigurationExample { - - // tag::code[] - @TestConfiguration(proxyBeanMethods = false) - public static class CustomizationConfiguration implements RestDocsWebTestClientConfigurationCustomizer { - - @Override - public void customize(WebTestClientRestDocumentationConfigurer configurer) { - configurer.snippets().withEncoding("UTF-8"); - } +@TestConfiguration(proxyBeanMethods = false) +public class AdvancedRestDocsConfiguration implements RestDocsWebTestClientConfigurationCustomizer { + @Override + public void customize(WebTestClientRestDocumentationConfigurer configurer) { + configurer.snippets().withEncoding("UTF-8"); } - // end::code[] } +// end::code[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientConfiguration.java index f242cb2a76..099f5ae350 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientConfiguration.java @@ -28,12 +28,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -/** - * A sample {@link SpringBootConfiguration @ConfigurationProperties} with an example - * controller. - * - * @author Stephane Nicoll - */ @SpringBootConfiguration @ImportAutoConfiguration({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class }) diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientTests.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientTests.java index bdbbb339fb..d5535f4cf0 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientTests.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/testing/webclient/SampleWebClientTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.docs.springbootfeatures.testing.webclient; +// tag::code[] import java.time.Duration; import org.junit.jupiter.api.Test; @@ -31,12 +32,6 @@ import org.springframework.http.HttpHeaders; import static org.assertj.core.api.Assertions.assertThat; -/** - * Example integration test that uses {@link TestRestTemplate}. - * - * @author Stephane Nicoll - */ -// tag::code[] @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) class SampleWebClientTests { @@ -50,7 +45,7 @@ class SampleWebClientTests { } @TestConfiguration(proxyBeanMethods = false) - static class Config { + static class RestTemplateBuilderConfiguration { @Bean RestTemplateBuilder restTemplateBuilder() { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/TomcatServerCustomizerExample.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/TomcatServerCustomizer.java similarity index 73% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/TomcatServerCustomizerExample.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/TomcatServerCustomizer.java index cab19252e7..49cbd9a0fb 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/TomcatServerCustomizerExample.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/springbootfeatures/webapplications/TomcatServerCustomizer.java @@ -16,25 +16,19 @@ package org.springframework.boot.docs.springbootfeatures.webapplications; +// tag::code[] import java.time.Duration; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.stereotype.Component; -/** - * Example of a {@link WebServerFactoryCustomizer} that uses a more narrowed server type. - * - * @author Stephane Nicoll - */ -// tag::code[] @Component -public class TomcatServerCustomizerExample implements WebServerFactoryCustomizer { +public class TomcatServerCustomizer implements WebServerFactoryCustomizer { @Override public void customize(TomcatServletWebServerFactory server) { - server.addConnectorCustomizers( - (tomcatConnector) -> tomcatConnector.setAsyncTimeout(Duration.ofSeconds(20).toMillis())); + server.addConnectorCustomizers((connector) -> connector.setAsyncTimeout(Duration.ofSeconds(20).toMillis())); } } diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportTests.java similarity index 89% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportTests.java index da851000f3..f03001cec3 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/actuator/MetricsHealthMicrometerExportTests.java @@ -36,12 +36,12 @@ import org.springframework.context.annotation.Import; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link MetricsHealthMicrometerExportExample}. + * Tests for {@link MetricsHealthMicrometerExport}. * * @author Phillip Webb */ @SpringBootTest -class MetricsHealthMicrometerExportExampleTests { +class MetricsHealthMicrometerExportTests { @Autowired private MeterRegistry registry; @@ -53,14 +53,14 @@ class MetricsHealthMicrometerExportExampleTests { } @Configuration(proxyBeanMethods = false) - @Import(MetricsHealthMicrometerExportExample.HealthMetricsConfiguration.class) + @Import(MetricsHealthMicrometerExport.HealthMetricsConfiguration.class) @ImportAutoConfiguration(classes = { HealthContributorAutoConfiguration.class, MetricsAutoConfiguration.class, HealthEndpointAutoConfiguration.class }) static class Config { @Bean - MetricsHealthMicrometerExportExample example() { - return new MetricsHealthMicrometerExportExample(); + MetricsHealthMicrometerExport example() { + return new MetricsHealthMicrometerExport(); } @Bean diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfigurationTests.java similarity index 92% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfigurationTests.java index 7053ef9b6f..a4b017ffca 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/BasicDataSourceConfigurationTests.java @@ -32,14 +32,14 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; /** - * Test for {@link BasicDataSourceExample}. + * Test for {@link BasicDataSourceConfiguration}. * * @author Stephane Nicoll */ @ExtendWith(SpringExtension.class) @SpringBootTest(properties = "app.datasource.jdbcUrl=jdbc:h2:mem:basic;DB_CLOSE_DELAY=-1") -@Import(BasicDataSourceExample.BasicDataSourceConfiguration.class) -class BasicDataSourceExampleTests { +@Import(BasicDataSourceConfiguration.class) +class BasicDataSourceConfigurationTests { @Autowired private ApplicationContext context; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/CompleteTwoDataSourcesExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfigurationTests.java similarity index 91% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/CompleteTwoDataSourcesExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfigurationTests.java index 86b2ffd551..4a549830ab 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/CompleteTwoDataSourcesExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/CompleteDataSourcesConfigurationTests.java @@ -32,14 +32,14 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link CompleteTwoDataSourcesExample}. + * Tests for {@link CompleteDataSourcesConfiguration}. * * @author Stephane Nicoll */ @ExtendWith(SpringExtension.class) @SpringBootTest -@Import(CompleteTwoDataSourcesExample.CompleteDataSourcesConfiguration.class) -class CompleteTwoDataSourcesExampleTests { +@Import(CompleteDataSourcesConfiguration.class) +class CompleteDataSourcesConfigurationTests { @Autowired private ApplicationContext context; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfigurationTests.java similarity index 91% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfigurationTests.java index caeea3d1c0..792a2ad853 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/ConfigurableDataSourceConfigurationTests.java @@ -33,15 +33,15 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; /** - * Test for {@link SimpleDataSourceExample}. + * Test for {@link ConfigurableDataSourceConfiguration}. * * @author Stephane Nicoll */ @ExtendWith(SpringExtension.class) @SpringBootTest(properties = { "app.datasource.url=jdbc:h2:mem:configurable;DB_CLOSE_DELAY=-1", "app.datasource.configuration.maximum-pool-size=42" }) -@Import(ConfigurableDataSourceExample.ConfigurableDataSourceConfiguration.class) -class ConfigurableDataSourceExampleTests { +@Import(ConfigurableDataSourceConfiguration.class) +class ConfigurableDataSourceConfigurationTests { @Autowired private ApplicationContext context; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfigurationTests.java similarity index 92% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfigurationTests.java index 373790bcf1..35a387c097 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourceConfigurationTests.java @@ -33,15 +33,15 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; /** - * Test for {@link SimpleDataSourceExample}. + * Test for {@link SimpleDataSourceConfiguration}. * * @author Stephane Nicoll */ @ExtendWith(SpringExtension.class) @SpringBootTest(properties = { "app.datasource.jdbc-url=jdbc:h2:mem:simple;DB_CLOSE_DELAY=-1", "app.datasource.maximum-pool-size=42" }) -@Import(SimpleDataSourceExample.SimpleDataSourceConfiguration.class) -class SimpleDataSourceExampleTests { +@Import(SimpleDataSourceConfiguration.class) +class SimpleDataSourceConfigurationTests { @Autowired private ApplicationContext context; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleTwoDataSourcesExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfigurationTests.java similarity index 92% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleTwoDataSourcesExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfigurationTests.java index bce2c431a0..c446893019 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleTwoDataSourcesExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/dataaccess/SimpleDataSourcesConfigurationTests.java @@ -33,15 +33,15 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link SimpleTwoDataSourcesExample}. + * Tests for {@link SimpleDataSourcesConfiguration}. * * @author Stephane Nicoll */ @ExtendWith(SpringExtension.class) @SpringBootTest(properties = { "app.datasource.second.url=jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1", "app.datasource.second.max-total=42" }) -@Import(SimpleTwoDataSourcesExample.SimpleDataSourcesConfiguration.class) -class SimpleTwoDataSourcesExampleTests { +@Import(SimpleDataSourcesConfiguration.class) +class SimpleDataSourcesConfigurationTests { @Autowired private ApplicationContext context; diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/embedded/TomcatLegacyCookieProcessorExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfigurationTests.java similarity index 84% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/embedded/TomcatLegacyCookieProcessorExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfigurationTests.java index 320e206acd..db2bb91633 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/context/embedded/TomcatLegacyCookieProcessorExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/embeddedwebservers/LegacyCookieProcessorConfigurationTests.java @@ -14,15 +14,13 @@ * limitations under the License. */ -package org.springframework.boot.docs.context.embedded; +package org.springframework.boot.docs.howto.embeddedwebservers; import org.apache.catalina.Context; import org.apache.tomcat.util.http.LegacyCookieProcessor; import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; -import org.springframework.boot.docs.howto.embeddedwebservers.TomcatLegacyCookieProcessorExample; -import org.springframework.boot.docs.howto.embeddedwebservers.TomcatLegacyCookieProcessorExample.LegacyCookieProcessorConfiguration; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor; @@ -33,11 +31,11 @@ import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link TomcatLegacyCookieProcessorExample}. + * Tests for {@link LegacyCookieProcessorConfiguration}. * * @author Andy Wilkinson */ -class TomcatLegacyCookieProcessorExampleTests { +class LegacyCookieProcessorConfigurationTests { @Test void cookieProcessorIsCustomized() { diff --git a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/springbootapplication/EnvironmentPostProcessorExampleTests.java b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/springbootapplication/ExampleEnvironmentPostProcessorTests.java similarity index 89% rename from spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/springbootapplication/EnvironmentPostProcessorExampleTests.java rename to spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/springbootapplication/ExampleEnvironmentPostProcessorTests.java index 931d8583c5..139aa89a5f 100644 --- a/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/springbootapplication/EnvironmentPostProcessorExampleTests.java +++ b/spring-boot-project/spring-boot-docs/src/test/java/org/springframework/boot/docs/howto/springbootapplication/ExampleEnvironmentPostProcessorTests.java @@ -24,18 +24,18 @@ import org.springframework.core.env.StandardEnvironment; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link EnvironmentPostProcessorExample}. + * Tests for {@link ExampleEnvironmentPostProcessor}. * * @author Stephane Nicoll */ -class EnvironmentPostProcessorExampleTests { +class ExampleEnvironmentPostProcessorTests { private final StandardEnvironment environment = new StandardEnvironment(); @Test void applyEnvironmentPostProcessor() { assertThat(this.environment.containsProperty("test.foo.bar")).isFalse(); - new EnvironmentPostProcessorExample().postProcessEnvironment(this.environment, new SpringApplication()); + new ExampleEnvironmentPostProcessor().postProcessEnvironment(this.environment, new SpringApplication()); assertThat(this.environment.containsProperty("test.foo.bar")).isTrue(); assertThat(this.environment.getProperty("test.foo.bar")).isEqualTo("value"); } diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index 694a83ca8f..79ab47a555 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -17,7 +17,7 @@ - +