@ -60,7 +60,7 @@ When reading the code, remember the following rules of thumb:
@@ -60,7 +60,7 @@ When reading the code, remember the following rules of thumb:
== Customize the Environment or ApplicationContext Before It Starts
A `SpringApplication` has `ApplicationListeners` and `ApplicationContextInitializers` that are used to apply customizations to the context or environment.
A `SpringApplication` has `ApplicationListener` and `ApplicationContextInitializer` implementations that are used to apply customizations to the context or environment.
Spring Boot loads a number of such customizations for use internally from `META-INF/spring.factories`.
There is more than one way to register additional customizations:
@ -97,7 +97,7 @@ This is too late to configure certain properties such as `+logging.*+` and `+spr
@@ -97,7 +97,7 @@ This is too late to configure certain properties such as `+logging.*+` and `+spr
[[howto.application.context-hierarchy]]
== Build an ApplicationContext Hierarchy (Adding a Parent or Root Context)
You can use the `ApplicationBuilder` class to create parent/child `ApplicationContext` hierarchies.
You can use the `SpringApplicationBuilder` class to create parent/child `ApplicationContext` hierarchies.
See xref:reference:features/spring-application.adoc#features.spring-application.fluent-builder-api[] in the "`Spring Boot Features`" section for more information.
@ -566,11 +566,11 @@ You can configure the roles by using the configprop:management.endpoint.health.r
@@ -566,11 +566,11 @@ You can configure the roles by using the configprop:management.endpoint.health.r
NOTE: If you have secured your application and wish to use `always`, your security configuration must permit access to the health endpoint for both authenticated and unauthenticated users.
Health information is collected from the content of a javadoc:org.springframework.boot.actuate.health.HealthContributorRegistry[] (by default, all javadoc:org.springframework.boot.actuate.health.HealthContributor[] instances defined in your `ApplicationContext`).
Spring Boot includes a number of auto-configured `HealthContributors`, and you can also write your own.
Spring Boot includes a number of auto-configured `HealthContributor` beans, and you can also write your own.
A `HealthContributor` can be either a `HealthIndicator` or a `CompositeHealthContributor`.
A `HealthIndicator` provides actual health information, including a `Status`.
A `CompositeHealthContributor` provides a composite of other `HealthContributors`.
A `CompositeHealthContributor` provides a composite of other `HealthContributor` instances.
Taken together, contributors form a tree structure to represent the overall system health.
By default, the final system health is derived by a `StatusAggregator`, which sorts the statuses from each `HealthIndicator` based on an ordered list of statuses.
@ -584,7 +584,7 @@ TIP: You can use the `HealthContributorRegistry` to register and unregister heal
@@ -584,7 +584,7 @@ TIP: You can use the `HealthContributorRegistry` to register and unregister heal
When appropriate, Spring Boot auto-configures the `HealthIndicators` listed in the following table.
When appropriate, Spring Boot auto-configures the `HealthIndicator` beans listed in the following table.
You can also enable or disable selected indicators by configuring `management.health.key.enabled`,
with the `key` listed in the following table:
@ -655,7 +655,7 @@ with the `key` listed in the following table:
@@ -655,7 +655,7 @@ with the `key` listed in the following table:
TIP: You can disable them all by setting the configprop:management.health.defaults.enabled[] property.
Additional `HealthIndicators` are available but are not enabled by default:
Additional `HealthIndicator` beans are available, but are not enabled by default:
[cols="3,4,6"]
|===
@ -752,7 +752,7 @@ The following table shows the default status mappings for the built-in statuses:
@@ -752,7 +752,7 @@ The following table shows the default status mappings for the built-in statuses:
For reactive applications, such as those that use Spring WebFlux, `ReactiveHealthContributor` provides a non-blocking contract for getting application health.
Similar to a traditional `HealthContributor`, health information is collected from the content of a javadoc:org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry[] (by default, all javadoc:org.springframework.boot.actuate.health.HealthContributor[] and javadoc:org.springframework.boot.actuate.health.ReactiveHealthContributor[] instances defined in your `ApplicationContext`).
Regular `HealthContributors` that do not check against a reactive API are executed on the elastic scheduler.
Regular `HealthContributor` instances that do not check against a reactive API are executed on the elastic scheduler.
TIP: In a reactive application, you should use the `ReactiveHealthContributorRegistry` to register and unregister health indicators at runtime.
If you need to register a regular `HealthContributor`, you should wrap it with `ReactiveHealthContributor#adapt`.
@ -769,7 +769,7 @@ TIP: To handle the error automatically, consider extending from `AbstractReactiv
@@ -769,7 +769,7 @@ TIP: To handle the error automatically, consider extending from `AbstractReactiv
@ -888,8 +888,8 @@ To customize the tags when using `WebClient`, provide a `@Bean` that implements
@@ -888,8 +888,8 @@ To customize the tags when using `WebClient`, provide a `@Bean` that implements
[[actuator.metrics.supported.tomcat]]
=== Tomcat Metrics
Auto-configuration enables the instrumentation of Tomcat only when an `MBeanRegistry` is enabled.
By default, the `MBeanRegistry` is disabled, but you can enable it by setting configprop:server.tomcat.mbeanregistry.enabled[] to `true`.
Auto-configuration enables the instrumentation of Tomcat only when an MBean `org.apache.tomcat.util.modeler.Registry` is enabled.
By default, the MBean registry is disabled, but you can enable it by setting configprop:server.tomcat.mbeanregistry.enabled[] to `true`.
Tomcat metrics are published under the `tomcat.` meter name.
@ -372,7 +372,7 @@ Furthermore, you can define a `RestClientOptions` bean to take further control o
@@ -372,7 +372,7 @@ Furthermore, you can define a `RestClientOptions` bean to take further control o
{url-spring-data-elasticsearch-site}[Spring Data Elasticsearch] ships `ReactiveElasticsearchClient` for querying Elasticsearch instances in a reactive fashion.
If you have Spring Data Elasticsearch and Reactor on the classpath, Spring Boot will auto-configure and register a `ReactiveElasticsearchClient`.
The `ReactiveElasticsearchclient` uses a transport that depends upon the previously described `RestClient`.
The `ReactiveElasticsearchClient` uses a transport that depends upon the previously described `RestClient`.
Therefore, the properties described previously can be used to configure the `ReactiveElasticsearchClient`.
Furthermore, you can define a `RestClientOptions` bean to take further control of the behavior of the transport.
@ -409,10 +409,10 @@ You can customize the locations to look for repositories and documents by using
@@ -409,10 +409,10 @@ You can customize the locations to look for repositories and documents by using
TIP: For complete details of Spring Data Elasticsearch, see the {url-spring-data-elasticsearch-docs}[reference documentation].
Spring Boot supports both classic and reactive Elasticsearch repositories, using the `ElasticsearchRestTemplate` or `ReactiveElasticsearchTemplate` beans.
Spring Boot supports both classic and reactive Elasticsearch repositories, using the `ElasticsearchTemplate` or `ReactiveElasticsearchTemplate` beans.
Most likely those beans are auto-configured by Spring Boot given the required dependencies are present.
If you wish to use your own template for backing the Elasticsearch repositories, you can add your own `ElasticsearchRestTemplate` or `ElasticsearchOperations` `@Bean`, as long as it is named `"elasticsearchTemplate"`.
If you wish to use your own template for backing the Elasticsearch repositories, you can add your own `ElasticsearchTemplate` or `ElasticsearchOperations` `@Bean`, as long as it is named `"elasticsearchTemplate"`.
Same applies to `ReactiveElasticsearchTemplate` and `ReactiveElasticsearchOperations`, with the bean name `"reactiveElasticsearchTemplate"`.
You can choose to disable the repositories support with the following property:
@ -172,7 +172,7 @@ TIP: If multiple auto-configurations have to be defined, there is no need to ord
@@ -172,7 +172,7 @@ TIP: If multiple auto-configurations have to be defined, there is no need to ord
Each test can use the runner to represent a particular use case.
For instance, the sample below invokes a user configuration (`UserConfiguration`) and checks that the auto-configuration backs off properly.
Invoking `run` provides a callback context that can be used with `AssertJ`.
Invoking `run` provides a callback context that can be used with AssertJ.
@ -195,7 +195,7 @@ You can use this prefix with the `spring.config.location` and `spring.config.add
@@ -195,7 +195,7 @@ You can use this prefix with the `spring.config.location` and `spring.config.add
For example, a `spring.config.import` value of `optional:file:./myconfig.properties` allows your application to start, even if the `myconfig.properties` file is missing.
If you want to ignore all `ConfigDataLocationNotFoundExceptions` and always continue to start your application, you can use the `spring.config.on-not-found` property.
If you want to ignore all `ConfigDataLocationNotFoundException` errors and always continue to start your application, you can use the `spring.config.on-not-found` property.
Set the value to `ignore` using `SpringApplication.setDefaultProperties(...)` or with a system/environment variable.
@ -1082,7 +1082,7 @@ NOTE: The preceding merging rules apply to properties from all property sources,
@@ -1082,7 +1082,7 @@ NOTE: The preceding merging rules apply to properties from all property sources,
=== Properties Conversion
Spring Boot attempts to coerce the external application properties to the right type when it binds to the `@ConfigurationProperties` beans.
If you need custom type conversion, you can provide a `ConversionService` bean (with a bean named `conversionService`) or custom property editors (through a `CustomEditorConfigurer` bean) or custom `Converters` (with bean definitions annotated as `@ConfigurationPropertiesBinding`).
If you need custom type conversion, you can provide a `ConversionService` bean (with a bean named `conversionService`) or custom property editors (through a `CustomEditorConfigurer` bean) or custom converters (with bean definitions annotated as `@ConfigurationPropertiesBinding`).
NOTE: As this bean is requested very early during the application lifecycle, make sure to limit the dependencies that your `ConversionService` is using.
Typically, any dependency that you require may not be fully initialized at creation time.
@ -28,7 +28,7 @@ TIP: To add additional logging during startup, you can override `logStartupInfo(
@@ -28,7 +28,7 @@ TIP: To add additional logging during startup, you can override `logStartupInfo(
[[features.spring-application.startup-failure]]
== Startup Failure
If your application fails to start, registered `FailureAnalyzers` get a chance to provide a dedicated error message and a concrete action to fix the problem.
If your application fails to start, registered `FailureAnalyzer` beans get a chance to provide a dedicated error message and a concrete action to fix the problem.
For instance, if you start a web application on port `8080` and that port is already in use, you should see something similar to the following message:
@ -101,7 +101,7 @@ NOTE: When a cache library offers both a native implementation and JSR-107 suppo
@@ -101,7 +101,7 @@ NOTE: When a cache library offers both a native implementation and JSR-107 suppo
TIP: Spring Boot has xref:io/hazelcast.adoc[general support for Hazelcast].
If a single `HazelcastInstance` is available, it is automatically reused for the `CacheManager` as well, unless the configprop:spring.cache.jcache.config[] property is specified.
There are two ways to customize the underlying `javax.cache.cacheManager`:
There are two ways to customize the underlying `javax.cache.CacheManager`:
* Caches can be created on startup by setting the configprop:spring.cache.cache-names[] property.
If a custom `javax.cache.configuration.Configuration` bean is defined, it is used to customize them.
@ -71,7 +71,7 @@ To use the factory bean, wire `StreamsBuilder` into your `@Bean` as shown in the
@@ -71,7 +71,7 @@ To use the factory bean, wire `StreamsBuilder` into your `@Bean` as shown in the
include-code::MyKafkaStreamsConfiguration[]
By default, the streams managed by the `StreamBuilder` object are started automatically.
By default, the streams managed by the `StreamsBuilder` object are started automatically.
You can customize this behavior using the configprop:spring.kafka.streams.auto-startup[] property.
@ -319,7 +319,7 @@ The following example shows a test class for Jackson:
@@ -319,7 +319,7 @@ The following example shows a test class for Jackson:
include-code::MyJsonTests[]
NOTE: JSON helper classes can also be used directly in standard unit tests.
To do so, call the `initFields` method of the helper in your `@Before` method if you do not use `@JsonTest`.
To do so, call the `initFields` method of the helper in your `@BeforeEach` method if you do not use `@JsonTest`.
If you use Spring Boot's AssertJ-based helpers to assert on a number value at a given JSON path, you might not be able to use `isEqualTo` depending on the type.
Instead, you can use AssertJ's `satisfies` to assert that the value matches the given condition.
`OutputCapture` is a JUnit `Extension` that you can use to capture `System.out` and `System.err` output.
`OutputCaptureExtension` is a JUnit `Extension` that you can use to capture `System.out` and `System.err` output.
To use it, add `@ExtendWith(OutputCaptureExtension.class)` and inject `CapturedOutput` as an argument to your test class constructor or test method as follows:
@ -486,7 +486,7 @@ To avoid this limitation, the `packages` method should not be used, and endpoint
@@ -486,7 +486,7 @@ To avoid this limitation, the `packages` method should not be used, and endpoint
For more advanced customizations, you can also register an arbitrary number of beans that implement `ResourceConfigCustomizer`.
All the registered endpoints should be `@Components` with HTTP resource annotations (`@GET` and others), as shown in the following example:
All the registered endpoints should be a `@Component` with HTTP resource annotations (`@GET` and others), as shown in the following example:
@ -107,8 +107,7 @@ The GraphQL WebSocket endpoint is off by default. To enable it:
@@ -107,8 +107,7 @@ The GraphQL WebSocket endpoint is off by default. To enable it:
Spring GraphQL provides a {url-spring-graphql-docs}/transports.html#server.interception[Web Interception] model.
This is quite useful for retrieving information from an HTTP request header and set it in the GraphQL context or fetching information from the same context and writing it to a response header.
With Spring Boot, you can declare a `WebInterceptor` bean to have it registered with the web transport.
With Spring Boot, you can declare a `WebGraphQlInterceptor` bean to have it registered with the web transport.
{url-spring-framework-docs}/web/webmvc-cors.html[Spring MVC] and {url-spring-framework-docs}/web/webflux-cors.html[Spring WebFlux] support CORS (Cross-Origin Resource Sharing) requests.
CORS is a critical part of the web config for GraphQL applications that are accessed from browsers using different domains.