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
pull/25115/head
Phillip Webb 4 years ago
parent 91ccc23462
commit 2a85427324

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

@ -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=*]
----

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

@ -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[]

@ -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[]

@ -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[]

@ -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 {
/**
* A simple configuration that exposes two data sources.
*/
@Configuration
public static class SimpleDataSourcesConfiguration {
@Configuration
public class CompleteDataSourcesConfiguration {
// tag::code[]
@Bean
@Primary
@ConfigurationProperties("app.datasource.first")
public DataSourceProperties firstDataSourceProperties() {
return new DataSourceProperties();
}
@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[]

@ -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[]
}
}

@ -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[]

@ -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[]

@ -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) {

@ -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[]

@ -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[]

@ -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 {
/**
* A configuration that defines dedicated settings and reuses
* {@link DataSourceProperties}.
*/
@Configuration(proxyBeanMethods = false)
public static class ConfigurableDataSourceConfiguration {
// 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[]
@Configuration
public class SimpleDataSourcesConfiguration {
@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 BasicDataSource secondDataSource() {
return DataSourceBuilder.create().type(BasicDataSource.class).build();
}
}
// end::code[]

@ -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<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
return (factory) -> factory
.addContextCustomizers((context) -> context.setCookieProcessor(new LegacyCookieProcessor()));
}
// end::code[]
@Configuration(proxyBeanMethods = false)
public class LegacyCookieProcessorConfiguration {
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
return (factory) -> factory
.addContextCustomizers((context) -> context.setCookieProcessor(new LegacyCookieProcessor()));
}
}
// end::code[]

@ -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<TomcatServletWebServerFactory> 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[]

@ -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<UndertowServletWebServerFactory> 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[]

@ -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[]

@ -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));
}
@Component
public class JerseySetStatusOverSendErrorConfig extends ResourceConfig {
public JerseySetStatusOverSendErrorConfig() {
register(Endpoint.class);
setProperties(Collections.singletonMap("jersey.config.server.response.setStatusOverSendError", true));
}
// end::code[]
static class Endpoint {
}
// end::code[]
}
class Endpoint {
}

@ -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();

@ -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[]

@ -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 {

@ -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[]

@ -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<String> words = new CopyOnWriteArrayList<>();
private final Dictionary dictionary;
Dictionary(MeterRegistry registry) {
registry.gaugeCollectionSize("dictionary.size", Tags.empty(), this.words);
}
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<String> getWords() {
return Collections.emptyList();
}
// end::code[]
}

@ -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;
}
}

@ -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 {

@ -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 {

@ -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 {

@ -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 {

@ -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<Integer, String> kStream(StreamsBuilder streamsBuilder) {
KStream<Integer, String> 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<Integer, String> kStream(StreamsBuilder streamsBuilder) {
KStream<Integer, String> 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[]

@ -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[]

@ -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[]

@ -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[]

@ -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[]

@ -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));
}
@Override
public void customize(RestTemplate restTemplate) {
HttpHost proxy = new HttpHost("proxy.example.com");
HttpClient httpClient = HttpClientBuilder.create().setRoutePlanner(new DefaultProxyRoutePlanner(proxy) {
static class CustomRoutePlanner extends DefaultProxyRoutePlanner {
@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);
}
CustomRoutePlanner(HttpHost proxy) {
super(proxy);
}
}).build();
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
@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);
}
}
// end::code[]
}
// end::code[]

@ -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[]

@ -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 {

@ -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 {
}

@ -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) {

@ -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 {

@ -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) {

@ -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 {

@ -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) {

@ -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) {

@ -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;

@ -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)

@ -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[]

@ -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 {

@ -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");
// ...
}

@ -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[]

@ -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[]

@ -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 })

@ -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() {

@ -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<TomcatServletWebServerFactory> {
public class TomcatServerCustomizer implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
@Override
public void customize(TomcatServletWebServerFactory server) {
server.addConnectorCustomizers(
(tomcatConnector) -> tomcatConnector.setAsyncTimeout(Duration.ofSeconds(20).toMillis()));
server.addConnectorCustomizers((connector) -> connector.setAsyncTimeout(Duration.ofSeconds(20).toMillis()));
}
}

@ -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

@ -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;

@ -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;

@ -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;

@ -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;

@ -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;

@ -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() {

@ -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");
}

@ -17,7 +17,7 @@
<suppress files="[\\/]src[\\/]test[\\/]java[\\/]" checks="NonEmptyAtclauseDescription" />
<suppress files="[\\/]autoconfigure[\\/].*Properties\.java" checks="JavadocType" />
<suppress files="[\\/]autoconfigure[\\/].*Properties\.java" checks="JavadocVariable" />
<suppress files="[\\/]spring-boot-docs[\\/]" checks="JavadocType" />
<suppress files="[\\/]spring-boot-docs[\\/]" checks="JavadocType|OneTopLevelClass" />
<suppress files="[\\/]spring-boot-smoke-tests[\\/]" checks="JavadocType" />
<suppress files="[\\/]spring-boot-smoke-tests[\\/]" checks="ImportControl" />
<suppress files="[\\/]spring-boot-smoke-tests[\\/]" id="mainCodeIllegalImportCheck" />

Loading…
Cancel
Save