Commit 711a0c19 authored by Phillip Webb's avatar Phillip Webb

Use consistent asciidoctor subs attribute

Closes gh-25101
parent 979fa12c
......@@ -17,7 +17,7 @@ If you want to fully disable the `/cloudfoundryapplication` endpoints, you can a
.application.properties
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
cloudfoundry:
......@@ -32,7 +32,7 @@ By default, the security verification for `/cloudfoundryapplication` endpoints m
If your Cloud Foundry UAA or Cloud Controller services use self-signed certificates, you need to set the following property:
.application.properties
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
cloudfoundry:
......@@ -50,7 +50,7 @@ If you expect the Cloud Foundry endpoints to always be available at `/cloudfound
The configuration will differ depending on the web server in use.
For Tomcat, the following configuration can be added:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/cloudfoundry/customcontextpath/MyCloudFoundryConfiguration.java[]
----
......@@ -11,7 +11,7 @@ Actuators can generate a large amount of motion from a small change.
To add the actuator to a Maven based project, add the following '`Starter`' dependency:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<dependencies>
<dependency>
......@@ -23,7 +23,7 @@ To add the actuator to a Maven based project, add the following '`Starter`' depe
For Gradle, use the following declaration:
[source,gradle,indent=0]
[source,gradle,indent=0,subs="verbatim"]
----
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
......
......@@ -120,7 +120,7 @@ By default, all endpoints except for `shutdown` are enabled.
To configure the enablement of an endpoint, use its `management.endpoint.<id>.enabled` property.
The following example enables the `shutdown` endpoint:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoint:
......@@ -131,7 +131,7 @@ The following example enables the `shutdown` endpoint:
If you prefer endpoint enablement to be opt-in rather than opt-out, set the configprop:management.endpoints.enabled-by-default[] property to `false` and use individual endpoint `enabled` properties to opt back in.
The following example enables the `info` endpoint and disables all other endpoints:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoints:
......@@ -282,7 +282,7 @@ Both `include` and `exclude` properties can be configured with a list of endpoin
For example, to stop exposing all endpoints over JMX and only expose the `health` and `info` endpoints, use the following property:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoints:
......@@ -294,7 +294,7 @@ For example, to stop exposing all endpoints over JMX and only expose the `health
`*` can be used to select all endpoints.
For example, to expose everything over HTTP except the `env` and `beans` endpoints, use the following properties:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoints:
......@@ -320,7 +320,7 @@ If you wish to configure custom security for HTTP endpoints, for example, only a
A typical Spring Security configuration might look something like the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/endpoints/security/typical/MySecurityConfiguration.java[]
----
......@@ -332,7 +332,7 @@ See the API documentation ({spring-boot-actuator-restapi-docs}[HTML] or {spring-
If you deploy applications behind a firewall, you may prefer that all your actuator endpoints can be accessed without requiring authentication.
You can do so by changing the configprop:management.endpoints.web.exposure.include[] property, as follows:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoints:
......@@ -343,7 +343,7 @@ You can do so by changing the configprop:management.endpoints.web.exposure.inclu
Additionally, if Spring Security is present, you would need to add custom security configuration that allows unauthenticated access to the endpoints as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/endpoints/security/exposeall/MySecurityConfiguration.java[]
----
......@@ -359,7 +359,7 @@ Endpoints automatically cache responses to read operations that do not take any
To configure the amount of time for which an endpoint will cache a response, use its `cache.time-to-live` property.
The following example sets the time-to-live of the `beans` endpoint's cache to 10 seconds:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoint:
......@@ -379,7 +379,7 @@ The "`discovery page`" is available on `/actuator` by default.
To disable the "`discovery page`", add the following property to your application properties:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoints:
......@@ -402,7 +402,7 @@ If you use Spring MVC or Spring WebFlux, Actuator's web endpoints can be configu
CORS support is disabled by default and is only enabled once the configprop:management.endpoints.web.cors.allowed-origins[] property has been set.
The following configuration permits `GET` and `POST` calls from the `example.com` domain:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoints:
......@@ -424,7 +424,7 @@ If both Jersey and Spring MVC are available, Spring MVC will be used.
The following example exposes a read operation that returns a custom object:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/endpoints/implementingcustom/MyEndpoint.java[tag=read]
----
......@@ -451,7 +451,7 @@ They can be made optional by annotating them with either `@javax.annotation.Null
Each root property in the JSON request body can be mapped to a parameter of the endpoint.
Consider the following JSON request body:
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{
"name": "test",
......@@ -461,7 +461,7 @@ Consider the following JSON request body:
This can be used to invoke a write operation that takes `String name` and `int counter` parameters, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/endpoints/implementingcustom/MyEndpoint.java[tag=write]
----
......@@ -740,7 +740,7 @@ You need to provide an implementation of the `health()` method and return a `Hea
The `Health` response should include a status and can optionally include additional details to be displayed.
The following code shows a sample `HealthIndicator` implementation:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/endpoints/health/writingcustomhealthindicators/MyHealthIndicator.java[]
----
......@@ -754,7 +754,7 @@ In such cases, a custom implementation of the {spring-boot-actuator-module-code}
For example, assume a new `Status` with code `FATAL` is being used in one of your `HealthIndicator` implementations.
To configure the severity order, add the following property to your application properties:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoint:
......@@ -771,7 +771,7 @@ Configuring a custom mapping disables the defaults mappings for `DOWN` and `OUT_
If you want to retain the default mappings they must be configured explicitly alongside any custom mappings.
For example, the following property maps `FATAL` to 503 (service unavailable) and retains the default mappings for `DOWN` and `OUT_OF_SERVICE`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoint:
......@@ -818,7 +818,7 @@ If you need to register a regular `HealthContributor`, you should wrap it using
To provide custom health information from a reactive API, you can register Spring beans that implement the {spring-boot-actuator-module-code}/health/ReactiveHealthIndicator.java[`ReactiveHealthIndicator`] interface.
The following code shows a sample `ReactiveHealthIndicator` implementation:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/endpoints/health/reactivehealthindicators/MyReactiveHealthIndicator.java[]
----
......@@ -872,7 +872,7 @@ It's sometimes useful to organize health indicators into groups that can be used
To create a health indicator group you can use the `management.endpoint.health.group.<name>` property and specify a list of health indicator IDs to `include` or `exclude`.
For example, to create a group that includes only database indicators you can define the following:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoint:
......@@ -886,7 +886,7 @@ You can then check the result by hitting `http://localhost:8080/actuator/health/
Similarly, to create a group that excludes the database indicators from the group and includes all the other indicators, you can define the following:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoint:
......@@ -899,7 +899,7 @@ Similarly, to create a group that excludes the database indicators from the grou
By default groups will inherit the same `StatusAggregator` and `HttpCodeStatusMapper` settings as the system health, however, these can also be defined on a per-group basis.
It's also possible to override the `show-details` and `roles` properties if required:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoint:
......@@ -940,7 +940,7 @@ They will also be exposed as separate HTTP Probes using <<actuator#actuator.endp
You can then configure your Kubernetes infrastructure with the following endpoint information:
[source,yml,indent=0]
[source,yml,indent=0,subs="verbatim"]
----
livenessProbe:
httpGet:
......@@ -976,7 +976,7 @@ In this case, a probe check could be successful even if the main application doe
Actuator configures the "liveness" and "readiness" probes as Health Groups; this means that all the <<actuator#actuator.endpoints.health.groups, Health Groups features>> are available for them.
You can, for example, configure additional Health Indicators:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoint:
......@@ -1108,7 +1108,7 @@ You can customize the data exposed by the `info` endpoint by setting `+info.*+`
All `Environment` properties under the `info` key are automatically exposed.
For example, you could add the following settings to your `application.properties` file:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
info:
app:
......@@ -1124,7 +1124,7 @@ Rather than hardcoding those values, you could also <<howto#howto.properties-and
Assuming you use Maven, you could rewrite the preceding example as follows:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
info:
app:
......@@ -1149,7 +1149,7 @@ By default, the endpoint exposes `git.branch`, `git.commit.id`, and `git.commit.
If you don't want any of these properties in the endpoint response, they need to be excluded from the `git.properties` file.
If you want to display the full git information (that is, the full content of `git.properties`), use the configprop:management.info.git.mode[] property, as follows:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
info:
......@@ -1159,7 +1159,7 @@ If you want to display the full git information (that is, the full content of `g
To disable the git commit information from the `info` endpoint completely, set the configprop:management.info.git.enabled[] property to `false`, as follows:
[source,properties,indent=0,configprops]
[source,properties,indent=0,subs="verbatim",configprops]
----
management.info.git.enabled=false
----
......@@ -1182,14 +1182,14 @@ To provide custom application information, you can register Spring beans that im
The following example contributes an `example` entry with a single value:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/endpoints/info/writingcustominfocontributors/MyInfoContributor.java[]
----
If you reach the `info` endpoint, you should see a response that contains the following additional entry:
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{
"example": {
......
......@@ -18,7 +18,7 @@ To solve this problem, you can set the configprop:spring.jmx.unique-names[] prop
You can also customize the JMX domain under which endpoints are exposed.
The following settings show an example of doing so in `application.properties`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
jmx:
......@@ -35,7 +35,7 @@ The following settings show an example of doing so in `application.properties`:
=== Disabling JMX Endpoints
If you do not want to expose endpoints over JMX, you can set the configprop:management.endpoints.jmx.exposure.exclude[] property to `*`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoints:
......@@ -52,7 +52,7 @@ Jolokia is a JMX-HTTP bridge that provides an alternative method of accessing JM
To use Jolokia, include a dependency to `org.jolokia:jolokia-core`.
For example, with Maven, you would add the following dependency:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>org.jolokia</groupId>
......@@ -75,7 +75,7 @@ Jolokia has a number of settings that you would traditionally configure by setti
With Spring Boot, you can use your `application.properties` file.
To do so, prefix the parameter with `management.endpoint.jolokia.config.`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoint:
......@@ -90,7 +90,7 @@ To do so, prefix the parameter with `management.endpoint.jolokia.config.`, as sh
==== Disabling Jolokia
If you use Jolokia but do not want Spring Boot to configure it, set the configprop:management.endpoint.jolokia.enabled[] property to `false`, as follows:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoint:
......
......@@ -21,7 +21,7 @@ These levels can be one of:
=== Configure a Logger
To configure a given logger, `POST` a partial entity to the resource's URI, as shown in the following example:
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{
"configuredLevel": "DEBUG"
......
......@@ -34,7 +34,7 @@ Most registries share common features.
For instance, you can disable a particular registry even if the Micrometer registry implementation is on the classpath.
For example, to disable Datadog:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -45,7 +45,7 @@ For example, to disable Datadog:
You can also disable all registries unless stated otherwise by the registry-specific property, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -56,7 +56,7 @@ You can also disable all registries unless stated otherwise by the registry-spec
Spring Boot will also add any auto-configured registries to the global static composite registry on the `Metrics` class unless you explicitly tell it not to:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -65,14 +65,14 @@ Spring Boot will also add any auto-configured registries to the global static co
You can register any number of `MeterRegistryCustomizer` beans to further configure the registry, such as applying common tags, before any meters are registered with the registry:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/gettingstarted/commontags/MyMeterRegistryConfiguration.java
----
You can apply customizations to particular registry implementations by being more specific about the generic type:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/gettingstarted/specifictype/MyMeterRegistryConfiguration.java
----
......@@ -91,7 +91,7 @@ Spring Boot also <<actuator#actuator.metrics.supported,configures built-in instr
By default, the AppOptics registry pushes metrics to `https://api.appoptics.com/v1/measurements` periodically.
To export metrics to SaaS {micrometer-registry-docs}/appOptics[AppOptics], your API token must be provided:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -107,7 +107,7 @@ To export metrics to SaaS {micrometer-registry-docs}/appOptics[AppOptics], your
By default, metrics are exported to {micrometer-registry-docs}/atlas[Atlas] running on your local machine.
The location of the https://github.com/Netflix/atlas[Atlas server] to use can be provided using:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -123,7 +123,7 @@ The location of the https://github.com/Netflix/atlas[Atlas server] to use can be
Datadog registry pushes metrics to https://www.datadoghq.com[datadoghq] periodically.
To export metrics to {micrometer-registry-docs}/datadog[Datadog], your API key must be provided:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -134,7 +134,7 @@ To export metrics to {micrometer-registry-docs}/datadog[Datadog], your API key m
You can also change the interval at which metrics are sent to Datadog:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -150,7 +150,7 @@ You can also change the interval at which metrics are sent to Datadog:
Dynatrace registry pushes metrics to the configured URI periodically.
To export metrics to {micrometer-registry-docs}/dynatrace[Dynatrace], your API token, device ID, and URI must be provided:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -163,7 +163,7 @@ To export metrics to {micrometer-registry-docs}/dynatrace[Dynatrace], your API t
You can also change the interval at which metrics are sent to Dynatrace:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -179,7 +179,7 @@ You can also change the interval at which metrics are sent to Dynatrace:
By default, metrics are exported to {micrometer-registry-docs}/elastic[Elastic] running on your local machine.
The location of the Elastic server to use can be provided using the following property:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -195,7 +195,7 @@ The location of the Elastic server to use can be provided using the following pr
By default, metrics are exported to {micrometer-registry-docs}/ganglia[Ganglia] running on your local machine.
The http://ganglia.sourceforge.net[Ganglia server] host and port to use can be provided using:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -212,7 +212,7 @@ The http://ganglia.sourceforge.net[Ganglia server] host and port to use can be p
By default, metrics are exported to {micrometer-registry-docs}/graphite[Graphite] running on your local machine.
The https://graphiteapp.org[Graphite server] host and port to use can be provided using:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -227,7 +227,7 @@ Micrometer provides a default `HierarchicalNameMapper` that governs how a dimens
TIP: To take control over this behavior, define your `GraphiteMeterRegistry` and supply your own `HierarchicalNameMapper`.
An auto-configured `GraphiteConfig` and `Clock` beans are provided unless you define your own:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/export/graphite/MyGraphiteConfiguration.java
----
......@@ -239,7 +239,7 @@ include::{docs-java}/actuator/metrics/export/graphite/MyGraphiteConfiguration.ja
By default, the Humio registry pushes metrics to https://cloud.humio.com periodically.
To export metrics to SaaS {micrometer-registry-docs}/humio[Humio], your API token must be provided:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -250,7 +250,7 @@ To export metrics to SaaS {micrometer-registry-docs}/humio[Humio], your API toke
You should also configure one or more tags to identify the data source to which metrics will be pushed:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -269,7 +269,7 @@ By default, metrics are exported to an {micrometer-registry-docs}/influx[Influx]
To export metrics to InfluxDB v2, configure the `org`, `bucket`, and authentication `token` for writing metrics.
The location of the https://www.influxdata.com[Influx server] to use can be provided using:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -286,7 +286,7 @@ Micrometer provides a hierarchical mapping to {micrometer-registry-docs}/jmx[JMX
By default, metrics are exported to the `metrics` JMX domain.
The domain to use can be provided using:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -300,7 +300,7 @@ Micrometer provides a default `HierarchicalNameMapper` that governs how a dimens
TIP: To take control over this behavior, define your `JmxMeterRegistry` and supply your own `HierarchicalNameMapper`.
An auto-configured `JmxConfig` and `Clock` beans are provided unless you define your own:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/export/jmx/MyJmxConfiguration.java
----
......@@ -312,7 +312,7 @@ include::{docs-java}/actuator/metrics/export/jmx/MyJmxConfiguration.java
By default, metrics are exported to {micrometer-registry-docs}/kairos[KairosDB] running on your local machine.
The location of the https://kairosdb.github.io/[KairosDB server] to use can be provided using:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -328,7 +328,7 @@ The location of the https://kairosdb.github.io/[KairosDB server] to use can be p
New Relic registry pushes metrics to {micrometer-registry-docs}/new-relic[New Relic] periodically.
To export metrics to https://newrelic.com[New Relic], your API key and account id must be provided:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -340,7 +340,7 @@ To export metrics to https://newrelic.com[New Relic], your API key and account i
You can also change the interval at which metrics are sent to New Relic:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -351,7 +351,7 @@ You can also change the interval at which metrics are sent to New Relic:
By default, metrics are published via REST calls but it is also possible to use the Java Agent API if you have it on the classpath:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -373,7 +373,7 @@ TIP: The endpoint is not available by default and must be exposed, see <<actuato
Here is an example `scrape_config` to add to `prometheus.yml`:
[source,yaml,indent=0]
[source,yaml,indent=0,subs="verbatim"]
----
scrape_configs:
- job_name: 'spring'
......@@ -385,7 +385,7 @@ Here is an example `scrape_config` to add to `prometheus.yml`:
For ephemeral or batch jobs which may not exist long enough to be scraped, https://github.com/prometheus/pushgateway[Prometheus Pushgateway] support can be used to expose their metrics to Prometheus.
To enable Prometheus Pushgateway support, add the following dependency to your project:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>io.prometheus</groupId>
......@@ -406,7 +406,7 @@ For advanced configuration, you can also provide your own `PrometheusPushGateway
SignalFx registry pushes metrics to {micrometer-registry-docs}/signalFx[SignalFx] periodically.
To export metrics to https://www.signalfx.com[SignalFx], your access token must be provided:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -417,7 +417,7 @@ To export metrics to https://www.signalfx.com[SignalFx], your access token must
You can also change the interval at which metrics are sent to SignalFx:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -436,7 +436,7 @@ This allows you to see what metrics are collected in the <<actuator#actuator.met
The in-memory backend disables itself as soon as you're using any of the other available backend.
You can also disable it explicitly:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -452,7 +452,7 @@ You can also disable it explicitly:
Stackdriver registry pushes metrics to https://cloud.google.com/stackdriver/[Stackdriver] periodically.
To export metrics to SaaS {micrometer-registry-docs}/stackdriver[Stackdriver], your Google Cloud project id must be provided:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -463,7 +463,7 @@ To export metrics to SaaS {micrometer-registry-docs}/stackdriver[Stackdriver], y
You can also change the interval at which metrics are sent to Stackdriver:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -480,7 +480,7 @@ The StatsD registry pushes metrics over UDP to a StatsD agent eagerly.
By default, metrics are exported to a {micrometer-registry-docs}/statsD[StatsD] agent running on your local machine.
The StatsD agent host, port, and protocol to use can be provided using:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -493,7 +493,7 @@ The StatsD agent host, port, and protocol to use can be provided using:
You can also change the StatsD line protocol to use (default to Datadog):
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -509,7 +509,7 @@ You can also change the StatsD line protocol to use (default to Datadog):
Wavefront registry pushes metrics to {micrometer-registry-docs}/wavefront[Wavefront] periodically.
If you are exporting metrics to https://www.wavefront.com/[Wavefront] directly, your API token must be provided:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -520,7 +520,7 @@ If you are exporting metrics to https://www.wavefront.com/[Wavefront] directly,
Alternatively, you may use a Wavefront sidecar or an internal proxy set up in your environment that forwards metrics data to the Wavefront API host:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -533,7 +533,7 @@ TIP: If publishing metrics to a Wavefront proxy (as described in https://docs.wa
You can also change the interval at which metrics are sent to Wavefront:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -793,7 +793,7 @@ Metrics are also tagged by the name of the `EntityManagerFactory` that is derive
To enable statistics, the standard JPA property `hibernate.generate_statistics` must be set to `true`.
You can enable that on the auto-configured `EntityManagerFactory` as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
jpa:
......@@ -884,14 +884,14 @@ Each metric is tagged with the following information by default:
To replace the default metric tags, define a `MongoCommandTagsProvider` bean, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/supported/mongodb/command/MyCommandTagsProviderConfiguration.java[]
----
To disable the auto-configured command metrics, set the following property:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -925,14 +925,14 @@ Each metric is tagged with the following information by default:
To replace the default metric tags, define a `MongoConnectionPoolTagsProvider` bean, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/supported/mongodb/connectionpool/MyConnectionPoolTagsProviderConfiguration.java[]
----
To disable the auto-configured connection pool metrics, set the following property:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -950,21 +950,21 @@ If supported, the annotation can be used either at the class-level or the method
For example, the following code shows how the annotation can be used to instrument all request mappings in a `@RestController`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/supported/timedannotation/all/MyController.java[]
----
If you only want to instrument a single mapping, you can use the annotation on the method instead of the class:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/supported/timedannotation/single/MyController.java[]
----
You can also combine class-level and method-level annotations if you want to change timing details for a specific method:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/supported/timedannotation/change/MyController.java[]
----
......@@ -978,14 +978,14 @@ Long task timers require a separate metric name, and can be stacked with a short
=== Registering Custom Metrics
To register custom metrics, inject `MeterRegistry` into your component, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/registeringcustom/MyBean.java[]
----
If your metrics depend on other beans, it is recommended that you use a `MeterBinder` to register them, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/registeringcustom/MyMeterBinderConfiguration.java[]
----
......@@ -1003,7 +1003,7 @@ If you need to apply customizations to specific `Meter` instances you can use th
For example, if you want to rename the `mytag.region` tag to `mytag.area` for all meter IDs beginning with `com.example`, you can do the following:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/actuator/metrics/customizing/MyMetricsFilterConfiguration.java[]
----
......@@ -1019,7 +1019,7 @@ These use the global registry that is not Spring-managed.
Common tags are generally used for dimensional drill-down on the operating environment like host, instance, region, stack, etc.
Commons tags are applied to all meters and can be configured as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......@@ -1041,7 +1041,7 @@ In addition to `MeterFilter` beans, it's also possible to apply a limited set of
Per-meter customizations apply to any all meter IDs that start with the given name.
For example, the following will disable any meters that have an ID starting with `example.remote`
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
metrics:
......
......@@ -17,7 +17,7 @@ Sometimes, it is useful to customize the prefix for the management endpoints.
For example, your application might already use `/actuator` for another purpose.
You can use the configprop:management.endpoints.web.base-path[] property to change the prefix for your management endpoint, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoints:
......@@ -34,7 +34,7 @@ If you want to map endpoints to a different path, you can use the configprop:man
The following example remaps `/actuator/health` to `/healthcheck`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoints:
......@@ -53,7 +53,7 @@ If, however, your application runs inside your own data center, you may prefer t
You can set the configprop:management.server.port[] property to change the HTTP port, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
server:
......@@ -70,7 +70,7 @@ If you want to use a custom management port on Cloud Foundry, you will need to e
When configured to use a custom port, the management server can also be configured with its own SSL by using the various `management.server.ssl.*` properties.
For example, doing so lets a management server be available over HTTP while the main application uses HTTPS, as shown in the following property settings:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
port: 8443
......@@ -87,7 +87,7 @@ For example, doing so lets a management server be available over HTTP while the
Alternatively, both the main server and the management server can use SSL but with different key stores, as follows:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
port: 8443
......@@ -115,7 +115,7 @@ NOTE: You can listen on a different address only when the port differs from the
The following example `application.properties` does not allow remote management connections:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
server:
......@@ -129,7 +129,7 @@ The following example `application.properties` does not allow remote management
=== Disabling HTTP Endpoints
If you do not want to expose endpoints over HTTP, you can set the management port to `-1`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
server:
......@@ -138,7 +138,7 @@ If you do not want to expose endpoints over HTTP, you can set the management por
This can be achieved using the configprop:management.endpoints.web.exposure.exclude[] property as well, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
management:
endpoints:
......
......@@ -4,7 +4,7 @@ The Spring Boot AntLib module provides basic Spring Boot support for Apache Ant.
You can use the module to create executable jars.
To use the module, you need to declare an additional `spring-boot` namespace in your `build.xml`, as shown in the following example:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<project xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:spring-boot="antlib:org.springframework.boot.ant"
......@@ -15,7 +15,7 @@ To use the module, you need to declare an additional `spring-boot` namespace in
You need to remember to start Ant using the `-lib` option, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim,attributes"]
----
$ ant -lib <directory containing spring-boot-antlib-{spring-boot-version}.jar>
----
......@@ -75,7 +75,7 @@ The following nested elements can be used with the task:
This section shows two examples of Ant tasks.
.Specify +start-class+
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<spring-boot:exejar destfile="target/my-application.jar"
classes="target/classes" start-class="com.example.MyApplication">
......@@ -89,7 +89,7 @@ This section shows two examples of Ant tasks.
----
.Detect +start-class+
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<exejar destfile="target/my-application.jar" classes="target/classes">
<lib>
......@@ -130,19 +130,19 @@ The following attributes are supported:
This section contains three examples of using `findmainclass`.
.Find and log
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<findmainclass classesroot="target/classes" />
----
.Find and set
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<findmainclass classesroot="target/classes" property="main-class" />
----
.Override and set
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<findmainclass mainclass="com.example.MainClass" property="main-class" />
----
......@@ -37,7 +37,7 @@ An exception is thrown if more than one candidate is found.
=== Example Repackage Implementation
The following example shows a typical repackage implementation:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/buildtoolplugins/otherbuildsystems/examplerepackageimplementation/MyBuildTool.java[]
----
......@@ -3,7 +3,7 @@
Spring Framework 4.0 has native support for a `beans{}` "`DSL`" (borrowed from https://grails.org/[Grails]), and you can embed bean definitions in your Groovy application scripts by using the same format.
This is sometimes a good way to include external features like middleware declarations, as shown in the following example:
[source,groovy,indent=0]
[source,groovy,indent=0,subs="verbatim"]
----
@Configuration(proxyBeanMethods = false)
class Application implements CommandLineRunner {
......
......@@ -3,7 +3,7 @@
Once you have installed the CLI, you can run it by typing `spring` and pressing Enter at the command line.
If you run `spring` without any arguments, a help screen is displayed, as follows:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ spring
usage: spring [--help] [--version]
......@@ -41,7 +41,7 @@ You can type `spring help` to get more details about any of the supported comman
The `version` command provides a quick way to check which version of Spring Boot you are using, as follows:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim,attributes"]
----
$ spring version
Spring CLI v{spring-boot-version}
......@@ -57,28 +57,28 @@ The Spring Boot CLI is completely self-contained, so you do not need any externa
The following example shows a "`hello world`" web application written in Groovy:
.hello.groovy
[source,groovy,indent=0,subs="verbatim,quotes,attributes"]
[source,groovy,indent=0,subs="verbatim"]
----
include::{docs-groovy}/cli/usingthecli/run/WebApplication.groovy[tag=*]
----
To compile and run the application, type the following command:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ spring run hello.groovy
----
To pass command-line arguments to the application, use `--` to separate the commands from the "`spring`" command arguments, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ spring run hello.groovy -- --server.port=9000
----
To set JVM command line arguments, you can use the `JAVA_OPTS` environment variable, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ JAVA_OPTS=-Xmx1024m spring run hello.groovy
----
......@@ -175,7 +175,7 @@ The annotation's value should specify the coordinates (`groupId:artifactId:versi
For example, consider the following declaration:
[source,groovy,indent=0]
[source,groovy,indent=0,subs="verbatim"]
----
include::{docs-groovy}/cli/usingthecli/run/customdependencymanagement/single/CustomDependencyManagement.groovy[tag=*]
----
......@@ -184,7 +184,7 @@ The preceding declaration picks up `custom-bom-1.0.0.pom` in a Maven repository
When you specify multiple BOMs, they are applied in the order in which you declare them, as shown in the following example:
[source,groovy,indent=0]
[source,groovy,indent=0,subs="verbatim"]
----
include::{docs-groovy}/cli/usingthecli/run/customdependencymanagement/multiple/CustomDependencyManagement.groovy[tag=*]
----
......@@ -305,7 +305,7 @@ If you do not use either of these shells (perhaps you are a Windows user), you c
From inside the embedded shell, you can run other commands directly:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim,attributes"]
----
$ version
Spring CLI v{spring-boot-version}
......@@ -322,7 +322,7 @@ To exit the embedded shell, press `ctrl-c`.
You can add extensions to the CLI by using the `install` command.
The command takes one or more sets of artifact coordinates in the format `group:artifact:version`, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ spring install com.example:spring-boot-cli-extension:1.0.0.RELEASE
----
......@@ -332,7 +332,7 @@ In addition to installing the artifacts identified by the coordinates you supply
To uninstall a dependency, use the `uninstall` command.
As with the `install` command, it takes one or more sets of artifact coordinates in the format of `group:artifact:version`, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ spring uninstall com.example:spring-boot-cli-extension:1.0.0.RELEASE
----
......@@ -341,7 +341,7 @@ It uninstalls the artifacts identified by the coordinates you supply and their d
To uninstall all additional dependencies, you can use the `--all` option, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ spring uninstall --all
----
......@@ -11,7 +11,7 @@ To use the processor, include a dependency on `spring-boot-configuration-process
With Maven the dependency should be declared as optional, as shown in the following example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -22,7 +22,7 @@ With Maven the dependency should be declared as optional, as shown in the follow
With Gradle, the dependency should be declared in the `annotationProcessor` configuration, as shown in the following example:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
dependencies {
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
......@@ -31,7 +31,7 @@ With Gradle, the dependency should be declared in the `annotationProcessor` conf
If you are using an `additional-spring-configuration-metadata.json` file, the `compileJava` task should be configured to depend on the `processResources` task, as shown in the following example:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
compileJava.inputs.files(processResources)
----
......@@ -45,7 +45,7 @@ There are several ways to do this.
With Maven, you can configure the `maven-apt-plugin` explicitly and add the dependency to the annotation processor only there.
You could also let the AspectJ plugin run all the processing and disable annotation processing in the `maven-compiler-plugin` configuration, as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......@@ -69,7 +69,7 @@ The annotation processor also supports the use of the `@Data`, `@Getter`, and `@
Consider the following example:
[source,java,indent=0,subs="verbatim,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/MyServerProperties.java[]
----
......@@ -86,14 +86,14 @@ Also, the annotation processor cannot auto-detect default values for ``Enum``s a
For cases where the default value could not be detected, <<configuration-metadata#configuration-metadata.annotation-processor.adding-additional-metadata,manual metadata>> should be provided.
Consider the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/MyMessagingProperties.java[]
----
In order to document default values for properties in the class above, you could add the following content to <<configuration-metadata#configuration-metadata.annotation-processor.adding-additional-metadata,the manual metadata of the module>>:
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{"properties": [
{
......@@ -117,7 +117,7 @@ The annotation processor automatically considers inner classes as nested propert
Rather than documenting the `ip` and `port` at the root of the namespace, we could create a sub-namespace for it.
Consider the updated example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/nestedproperties/MyServerProperties.java[]
----
......
......@@ -3,7 +3,7 @@
Configuration metadata files are located inside jars under `META-INF/spring-configuration-metadata.json`.
They use a JSON format with items categorized under either "`groups`" or "`properties`" and additional values hints categorized under "hints", as shown in the following example:
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{"groups": [
{
......@@ -68,7 +68,7 @@ They use a JSON format with items categorized under either "`groups`" or "`prope
Each "`property`" is a configuration item that the user specifies with a given value.
For example, `server.port` and `server.address` might be specified in `application.properties`, as follows:
[source,properties,indent=0,configprops]
[source,properties,indent=0,subs="verbatim",configprops]
----
server.port=9090
server.address=127.0.0.1
......@@ -207,7 +207,7 @@ Deprecation can also be specified declaratively in code by adding the `@Deprecat
For instance, assume that the `my.app.target` property was confusing and was renamed to `my.app.name`.
The following example shows how to handle that situation:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/configurationmetadata/format/group/MyProperties.java[]
----
......
......@@ -18,7 +18,7 @@ The special `.keys` and `.values` suffixes must refer to the keys and the values
Assume a `my.contexts` maps magic `String` values to an integer, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/configurationmetadata/manualhints/valuehint/MyProperties.java[]
----
......@@ -26,7 +26,7 @@ include::{docs-java}/configurationmetadata/manualhints/valuehint/MyProperties.ja
The magic values are (in this example) are `sample1` and `sample2`.
In order to offer additional content assistance for the keys, you could add the following JSON to <<configuration-metadata#configuration-metadata.annotation-processor.adding-additional-metadata,the manual metadata of the module>>:
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{"hints": [
{
......@@ -101,7 +101,7 @@ This provider is typically used if you have a list of values and any extra value
The following example offers `on` and `off` as auto-completion values for `system.state`:
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{"hints": [
{
......@@ -152,7 +152,7 @@ This provider supports the following parameters:
The following metadata snippet corresponds to the standard `server.servlet.jsp.class-name` property that defines the `JspServlet` class name to use:
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{"hints": [
{
......@@ -202,7 +202,7 @@ TIP: If multiple values can be provided, use a `Collection` or _Array_ type to t
The following metadata snippet corresponds to the standard `spring.liquibase.change-log` property that defines the path to the changelog to use.
It is actually used internally as a `org.springframework.core.io.Resource` but cannot be exposed as such, because we need to keep the original String value to pass it to the Liquibase API.
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{"hints": [
{
......@@ -246,7 +246,7 @@ The following metadata snippet corresponds to the standard `logging.level` prope
Keys are _logger names_, and values correspond to the standard log levels or any custom level.
As Spring Boot defines a few logger groups out-of-the-box, dedicated value hints have been added for those.
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{"hints": [
{
......@@ -326,7 +326,7 @@ This provider supports the following parameters:
The following metadata snippet corresponds to the standard `spring.jmx.server` property that defines the name of the `MBeanServer` bean to use:
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{"hints": [
{
......@@ -354,7 +354,7 @@ The **spring-profile-name** provider auto-completes the Spring profiles that are
The following metadata snippet corresponds to the standard `spring.profiles.active` property that defines the name of the Spring profile(s) to enable:
[source,json,indent=0]
[source,json,indent=0,subs="verbatim"]
----
{"hints": [
{
......
......@@ -27,7 +27,7 @@ Once you have built your application (by using, for example, `mvn clean package`
Be sure to have https://docs.cloudfoundry.org/cf-cli/getting-started.html#login[logged in with your `cf` command line client] before pushing an application.
The following line shows using the `cf push` command to deploy an application:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ cf push acloudyspringtime -p target/demo-0.0.1-SNAPSHOT.jar
----
......@@ -39,7 +39,7 @@ If there is a Cloud Foundry https://docs.cloudfoundry.org/devguide/deploy-apps/m
At this point, `cf` starts uploading your application, producing output similar to the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim,quotes"]
----
Uploading acloudyspringtime... *OK*
Preparing to start acloudyspringtime... *OK*
......@@ -68,7 +68,7 @@ Congratulations! The application is now live!
Once your application is live, you can verify the status of the deployed application by using the `cf apps` command, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ cf apps
Getting applications in ...
......@@ -93,7 +93,7 @@ Process-scoped environment variables are language agnostic.
Environment variables do not always make for the easiest API, so Spring Boot automatically extracts them and flattens the data into properties that can be accessed through Spring's `Environment` abstraction, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/deployment/cloud/cloudfoundry/bindingtoservices/MyBean.java[]
----
......@@ -124,7 +124,7 @@ You can configure a sleep execution in a preStop handler to avoid requests being
This sleep should be long enough for new requests to stop being routed to the pod and its duration will vary from deployment to deployment.
The preStop handler can be configured via the PodSpec in the pod's configuration file as follows:
[source,yml,indent=0]
[source,yml,indent=0,subs="verbatim"]
----
spec:
containers:
......@@ -161,7 +161,7 @@ The `$PORT` environment variable is assigned to us by the Heroku PaaS.
This should be everything you need.
The most common deployment workflow for Heroku deployments is to `git push` the code to production, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim,quotes"]
----
$ git push heroku main
......@@ -270,7 +270,7 @@ By default, Elastic Beanstalk uploads sources and compiles them in AWS.
However, it is best to upload the binaries instead.
To do so, add lines similar to the following to your `.elasticbeanstalk/config.yml` file:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
deploy:
artifact: target/demo-0.0.1-SNAPSHOT.jar
......@@ -321,7 +321,7 @@ If your executable jar or war contains an https://boxfuse.com/docs/payloads/spri
At this point, `boxfuse` creates an image for your application, uploads it, and configures and starts the necessary resources on AWS, resulting in output similar to the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
Fusing Image for myapp-1.0.jar ...
Image fused in 00:06.838s (53937 K) -> axelfontaine/myapp:1.0
......@@ -362,7 +362,7 @@ Follow https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/appe
Alternatively, App Engine Flex requires you to create an `app.yaml` file to describe the resources your app requires.
Normally, you put this file in `src/main/appengine`, and it should resemble the following file:
[source,yaml,indent=0]
[source,yaml,indent=0,subs="verbatim"]
----
service: default
......@@ -388,7 +388,7 @@ Normally, you put this file in `src/main/appengine`, and it should resemble the
You can deploy the app (for example, with a Maven plugin) by adding the project ID to the build configuration, as shown in the following example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<plugin>
<groupId>com.google.cloud.tools</groupId>
......
......@@ -15,7 +15,7 @@ A standard-format jar file that contains one or more zip64-format nested jars ca
To create a '`fully executable`' jar with Maven, use the following plugin configuration:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<plugin>
<groupId>org.springframework.boot</groupId>
......@@ -28,7 +28,7 @@ To create a '`fully executable`' jar with Maven, use the following plugin config
The following example shows the equivalent Gradle configuration:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
bootJar {
launchScript()
......@@ -66,7 +66,7 @@ The script supports the following features:
Assuming that you have a Spring Boot application installed in `/var/myapp`, to install a Spring Boot application as an `init.d` service, create a symlink, as follows:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp
----
......@@ -74,7 +74,7 @@ Assuming that you have a Spring Boot application installed in `/var/myapp`, to i
Once installed, you can start and stop the service in the usual way.
For example, on a Debian-based system, you could start it with the following command:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ service myapp start
----
......@@ -84,7 +84,7 @@ TIP: If your application fails to start, check the log file written to `/var/log
You can also flag the application to start automatically by using your standard operating system tools.
For example, on Debian, you could use the following command:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ update-rc.d myapp defaults <priority>
----
......@@ -101,7 +101,7 @@ When the environment variable is not set, the user who owns the jar file is used
You should never run a Spring Boot application as `root`, so `RUN_AS_USER` should never be root and your application's jar file should never be owned by root.
Instead, create a specific user to run your application and set the `RUN_AS_USER` environment variable or use `chown` to make it the owner of the jar file, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ chown bootapp:bootapp your-app.jar
----
......@@ -114,7 +114,7 @@ For example, you can set the account's shell to `/usr/sbin/nologin`.
You should also take steps to prevent the modification of your application's jar file.
Firstly, configure its permissions so that it cannot be written and can only be read or executed by its owner, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ chmod 500 your-app.jar
----
......@@ -123,7 +123,7 @@ Second, you should also take steps to limit the damage if your application or th
If an attacker does gain access, they could make the jar file writable and change its contents.
One way to protect against this is to make it immutable by using `chattr`, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ sudo chattr +i your-app.jar
----
......@@ -134,7 +134,7 @@ If root is used to control the application's service and you <<deployment#deploy
It should be secured accordingly.
Use `chmod` so that the file can only be read by the owner and use `chown` to make root the owner, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ chmod 400 your-app.conf
$ sudo chown root:root your-app.conf
......@@ -174,7 +174,7 @@ Consult the https://www.freedesktop.org/software/systemd/man/systemd.service.htm
To flag the application to start automatically on system boot, use the following command:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ systemctl enable myapp.service
----
......@@ -370,7 +370,7 @@ The file is expected to be next to the jar file and have the same name but suffi
For example, a jar named `/var/myapp/myapp.jar` uses the configuration file named `/var/myapp/myapp.conf`, as shown in the following example:
.myapp.conf
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
JAVA_OPTS=-Xmx1024M
LOG_FOLDER=/custom/log/folder
......
......@@ -9,7 +9,7 @@ NOTE: Check the {spring-framework-docs}/integration.html#cache[relevant section]
In a nutshell, to add caching to an operation of your service add the relevant annotation to its method, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/caching/MyMathService.java[]
----
......@@ -59,7 +59,7 @@ If you add dependencies manually, you must include `spring-context-support` in o
If the `CacheManager` is auto-configured by Spring Boot, you can further tune its configuration before it is fully initialized by exposing a bean that implements the `CacheManagerCustomizer` interface.
The following example sets a flag to say that `null` values should be passed down to the underlying map:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/caching/provider/MyCacheManagerConfiguration.java[]
----
......@@ -86,7 +86,7 @@ Any other compliant library can be added as well.
It might happen that more than one provider is present, in which case the provider must be explicitly specified.
Even if the JSR-107 standard does not enforce a standardized way to define the location of the configuration file, Spring Boot does its best to accommodate setting a cache with implementation details, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
# Only necessary if more than one provider is present
spring:
......@@ -118,7 +118,7 @@ https://www.ehcache.org/[EhCache] 2.x is used if a file named `ehcache.xml` can
If EhCache 2.x is found, the `EhCacheCacheManager` provided by the `spring-boot-starter-cache` "`Starter`" is used to bootstrap the cache manager.
An alternate configuration file can be provided as well, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
cache:
......@@ -140,7 +140,7 @@ If a `HazelcastInstance` has been auto-configured, it is automatically wrapped i
https://infinispan.org/[Infinispan] has no default configuration file location, so it must be specified explicitly.
Otherwise, the default bootstrap is used.
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
cache:
......@@ -163,7 +163,7 @@ If Spring Data Couchbase is available and Couchbase is <<features#features.nosql
It is possible to create additional caches on startup by setting the configprop:spring.cache.cache-names[] property and cache defaults can be configured by using `spring.cache.couchbase.*` properties.
For instance, the following configuration creates `cache1` and `cache2` caches with an entry _expiration_ of 10 minutes:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
cache:
......@@ -175,7 +175,7 @@ For instance, the following configuration creates `cache1` and `cache2` caches w
If you need more control over the configuration, consider registering a `CouchbaseCacheManagerBuilderCustomizer` bean.
The following example shows a customizer that configures a specific entry expiration for `cache1` and `cache2`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/caching/provider/couchbase/MyCouchbaseCacheManagerConfiguration.java[]
----
......@@ -188,7 +188,7 @@ If https://redis.io/[Redis] is available and configured, a `RedisCacheManager` i
It is possible to create additional caches on startup by setting the configprop:spring.cache.cache-names[] property and cache defaults can be configured by using `spring.cache.redis.*` properties.
For instance, the following configuration creates `cache1` and `cache2` caches with a _time to live_ of 10 minutes:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
cache:
......@@ -206,7 +206,7 @@ This can be useful if you're looking for customizing the default serialization s
If you need more control over the configuration, consider registering a `RedisCacheManagerBuilderCustomizer` bean.
The following example shows a customizer that configures a specific time to live for `cache1` and `cache2`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/caching/provider/redis/MyRedisCacheManagerConfiguration.java[]
----
......@@ -225,7 +225,7 @@ Caches can be created on startup by setting the configprop:spring.cache.cache-na
For instance, the following configuration creates `cache1` and `cache2` caches with a maximum size of 500 and a _time to live_ of 10 minutes
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
cache:
......@@ -247,7 +247,7 @@ This is the default if no caching library is present in your application.
By default, caches are created as needed, but you can restrict the list of available caches by setting the `cache-names` property.
For instance, if you want only `cache1` and `cache2` caches, set the `cache-names` property as follows:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
cache:
......@@ -264,7 +264,7 @@ This is similar to the way the "real" cache providers behave if you use an undec
When `@EnableCaching` is present in your configuration, a suitable cache configuration is expected as well.
If you need to disable caching altogether in certain environments, force the cache type to `none` to use a no-op implementation, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
cache:
......
......@@ -23,7 +23,7 @@ Out-of-the-box, the following layers are supported:
The following shows an example of a `layers.idx` file:
[source,yaml,indent=0]
[source,yaml,indent=0,subs="verbatim"]
----
- "dependencies":
- BOOT-INF/lib/library1.jar
......
......@@ -76,7 +76,7 @@ This mechanism does not apply the same way to `@Bean` methods where typically th
To handle this scenario, a separate `@Configuration` class can be used to isolate the condition, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingautoconfiguration/conditionannotations/classconditions/MyAutoConfiguration.java[]
----
......@@ -93,7 +93,7 @@ The `search` attribute lets you limit the `ApplicationContext` hierarchy that sh
When placed on a `@Bean` method, the target type defaults to the return type of the method, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingautoconfiguration/conditionannotations/beanconditions/MyAutoConfiguration.java[]
----
......@@ -154,7 +154,7 @@ Concretely, each test should create a well defined `ApplicationContext` that rep
`ApplicationContextRunner` is usually defined as a field of the test class to gather the base, common configuration.
The following example makes sure that `MyServiceAutoConfiguration` is always invoked:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingautoconfiguration/testing/MyServiceAutoConfigurationTests.java[tag=runner]
----
......@@ -165,14 +165,14 @@ 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`.
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingautoconfiguration/testing/MyServiceAutoConfigurationTests.java[tag=test-user-config]
----
It is also possible to easily customize the `Environment`, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingautoconfiguration/testing/MyServiceAutoConfigurationTests.java[tag=test-env]
----
......@@ -181,7 +181,7 @@ The runner can also be used to display the `ConditionEvaluationReport`.
The report can be printed at `INFO` or `DEBUG` level.
The following example shows how to use the `ConditionEvaluationReportLoggingListener` to print the report in auto-configuration tests.
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingautoconfiguration/testing/MyConditionEvaluationReportingTests.java[]
----
......@@ -200,7 +200,7 @@ It is also possible to test what happens when a particular class and/or package
Spring Boot ships with a `FilteredClassLoader` that can easily be used by the runner.
In the following example, we assert that if `MyService` is not present, the auto-configuration is properly disabled:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingautoconfiguration/testing/MyServiceAutoConfigurationTests.java[tag=test-classloader]
----
......@@ -249,7 +249,7 @@ As a rule of thumb, prefix all your keys with a namespace that you own (e.g. `ac
Make sure that configuration keys are documented by adding field javadoc for each property, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingautoconfiguration/customstarter/configurationkeys/AcmeProperties.java[]
----
......@@ -282,7 +282,7 @@ Spring Boot uses an annotation processor to collect the conditions on auto-confi
If that file is present, it is used to eagerly filter auto-configurations that do not match, which will improve startup time.
It is recommended to add the following dependency in a module that contains auto-configurations:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -293,7 +293,7 @@ It is recommended to add the following dependency in a module that contains auto
If you have defined auto-configurations directly in your application, make sure to configure the `spring-boot-maven-plugin` to prevent the `repackage` goal from adding the dependency into the fat jar:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<project>
<build>
......@@ -317,7 +317,7 @@ If you have defined auto-configurations directly in your application, make sure
With Gradle 4.5 and earlier, the dependency should be declared in the `compileOnly` configuration, as shown in the following example:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
dependencies {
compileOnly "org.springframework.boot:spring-boot-autoconfigure-processor"
......@@ -326,7 +326,7 @@ With Gradle 4.5 and earlier, the dependency should be declared in the `compileOn
With Gradle 4.6 and later, the dependency should be declared in the `annotationProcessor` configuration, as shown in the following example:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
dependencies {
annotationProcessor "org.springframework.boot:spring-boot-autoconfigure-processor"
......
......@@ -17,7 +17,7 @@ Methods in your controller are mapped to HTTP by using `@RequestMapping` annotat
The following code shows a typical `@RestController` that serves JSON data:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springmvc/MyRestController.java[]
----
......@@ -67,7 +67,7 @@ By default, strings are encoded in `UTF-8`.
If you need to add or customize converters, you can use Spring Boot's `HttpMessageConverters` class, as shown in the following listing:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springmvc/messageconverters/MyHttpMessageConvertersConfiguration.java[]
----
......@@ -85,7 +85,7 @@ Custom serializers are usually https://github.com/FasterXML/jackson-docs/wiki/Ja
You can use the `@JsonComponent` annotation directly on `JsonSerializer`, `JsonDeserializer` or `KeyDeserializer` implementations.
You can also use it on classes that contain serializers/deserializers as inner classes, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springmvc/json/MyJsonComponent.java[]
----
......@@ -98,7 +98,7 @@ See {spring-boot-module-api}/jackson/JsonObjectSerializer.html[`JsonObjectSerial
The example above can be rewritten to use `JsonObjectSerializer`/`JsonObjectDeserializer` as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springmvc/json/object/MyJsonComponent.java[]
----
......@@ -123,7 +123,7 @@ Most of the time, this does not happen (unless you modify the default MVC config
By default, resources are mapped on `+/**+`, but you can tune that with the configprop:spring.mvc.static-path-pattern[] property.
For instance, relocating all resources to `/resources/**` can be achieved as follows:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
mvc:
......@@ -150,7 +150,7 @@ Otherwise, all Webjars resolve as a `404`.
To use cache busting, the following configuration configures a cache busting solution for all static resources, effectively adding a content hash, such as `<link href="/css/spring-2a2d595e6ed9a0b24f027f2b63b134d6.css"/>`, in URLs:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
web:
......@@ -170,7 +170,7 @@ When loading resources dynamically with, for example, a JavaScript module loader
That is why other strategies are also supported and can be combined.
A "fixed" strategy adds a static version string in the URL without changing the file name, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
web:
......@@ -218,7 +218,7 @@ Nowadays, Content Negotiation is much more reliable.
There are other ways to deal with HTTP clients that don't consistently send proper "Accept" request headers.
Instead of using suffix matching, we can use a query parameter to ensure that requests like `"GET /projects/spring-boot?format=json"` will be mapped to `@GetMapping("/projects/spring-boot")`:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
spring:
mvc:
......@@ -228,7 +228,7 @@ Instead of using suffix matching, we can use a query parameter to ensure that re
Or if you prefer to use a different parameter name:
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
[source,properties,indent=0,subs="verbatim"]
----
spring:
mvc:
......@@ -239,7 +239,7 @@ Or if you prefer to use a different parameter name:
Most standard media types are supported out-of-the-box, but you can also define new ones:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
spring:
mvc:
......@@ -253,7 +253,7 @@ Most standard media types are supported out-of-the-box, but you can also define
Suffix pattern matching is deprecated and will be removed in a future release.
If you understand the caveats and would still like your application to use suffix pattern matching, the following configuration is required:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
spring:
mvc:
......@@ -265,7 +265,7 @@ If you understand the caveats and would still like your application to use suffi
Alternatively, rather than open all suffix patterns, it's more secure to only support registered suffix patterns:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
spring:
mvc:
......@@ -279,7 +279,7 @@ As of Spring Framework 5.3, Spring MVC supports several implementation strategie
It was previously only supporting the `AntPathMatcher` strategy, but it now also offers `PathPatternParser`.
Spring Boot now provides a configuration property to choose and opt in the new strategy:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
mvc:
......@@ -347,7 +347,7 @@ To do so, extend `BasicErrorController`, add a public method with a `@RequestMap
You can also define a class annotated with `@ControllerAdvice` to customize the JSON document to return for a particular controller and/or exception type, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springmvc/errorhandling/MyControllerAdvice.java[]
----
......@@ -357,7 +357,7 @@ In the preceding example, if `YourException` is thrown by a controller defined i
In some cases, errors handled at the controller level are not recorded by the <<actuator#actuator.metrics.supported.spring-mvc, metrics infrastructure>>.
Applications can ensure that such exceptions are recorded with the request metrics by setting the handled exception as a request attribute:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springmvc/errorhandling/MyController.java[]
----
......@@ -372,7 +372,7 @@ The name of the file should be the exact status code or a series mask.
For example, to map `404` to a static HTML file, your directory structure would be as follows:
[source,indent=0,subs="verbatim,quotes,attributes"]
[source,indent=0,subs="verbatim"]
----
src/
+- main/
......@@ -387,7 +387,7 @@ For example, to map `404` to a static HTML file, your directory structure would
To map all `5xx` errors by using a FreeMarker template, your directory structure would be as follows:
[source,indent=0,subs="verbatim,quotes,attributes"]
[source,indent=0,subs="verbatim"]
----
src/
+- main/
......@@ -402,7 +402,7 @@ To map all `5xx` errors by using a FreeMarker template, your directory structure
For more complex mappings, you can also add beans that implement the `ErrorViewResolver` interface, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springmvc/errorhandling/errorpages/MyErrorViewResolver.java[]
----
......@@ -417,14 +417,14 @@ The `ErrorController` then picks up any unhandled exceptions.
For applications that do not use Spring MVC, you can use the `ErrorPageRegistrar` interface to directly register `ErrorPages`.
This abstraction works directly with the underlying embedded servlet container and works even if you do not have a Spring MVC `DispatcherServlet`.
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springmvc/errorhandling/errorpageswithoutspringmvc/MyErrorPagesConfiguration.java[]
----
NOTE: If you register an `ErrorPage` with a path that ends up being handled by a `Filter` (as is common with some non-Spring web frameworks, like Jersey and Wicket), then the `Filter` has to be explicitly registered as an `ERROR` dispatcher, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springmvc/errorhandling/errorpageswithoutspringmvc/MyFilterConfiguration.java[]
----
......@@ -467,7 +467,7 @@ As of version 4.2, Spring MVC {spring-framework-docs}/web.html#mvc-cors[supports
Using {spring-framework-docs}/web.html#mvc-cors-controller[controller method CORS configuration] with {spring-framework-api}/web/bind/annotation/CrossOrigin.html[`@CrossOrigin`] annotations in your Spring Boot application does not require any specific configuration.
{spring-framework-docs}/web.html#mvc-cors-global[Global CORS configuration] can be defined by registering a `WebMvcConfigurer` bean with a customized `addCorsMappings(CorsRegistry)` method, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springmvc/cors/MyCorsConfiguration.java[]
----
......@@ -482,19 +482,19 @@ Unlike Spring MVC, it does not require the Servlet API, is fully asynchronous an
Spring WebFlux comes in two flavors: functional and annotation-based.
The annotation-based one is quite close to the Spring MVC model, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springwebflux/MyRestController.java[]
----
"`WebFlux.fn`", the functional variant, separates the routing configuration from the actual handling of the requests, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springwebflux/MyRoutingConfiguration.java[]
----
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springwebflux/MyUserHandler.java[]
----
......@@ -538,7 +538,7 @@ For example, `+spring.jackson.*+` configuration keys are applied to the Jackson
If you need to add or customize codecs, you can create a custom `CodecCustomizer` component, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springwebflux/httpcodecs/MyCodecsConfiguration.java[]
----
......@@ -555,7 +555,7 @@ It uses the `ResourceWebHandler` from Spring WebFlux so that you can modify that
By default, resources are mapped on `+/**+`, but you can tune that by setting the configprop:spring.webflux.static-path-pattern[] property.
For instance, relocating all resources to `/resources/**` can be achieved as follows:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
webflux:
......@@ -612,7 +612,7 @@ For that, you can add a bean of type `ErrorAttributes`.
To change the error handling behavior, you can implement `ErrorWebExceptionHandler` and register a bean definition of that type.
Because a `ErrorWebExceptionHandler` is quite low-level, Spring Boot also provides a convenient `AbstractErrorWebExceptionHandler` to let you handle errors in a WebFlux functional way, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springwebflux/errorhandling/MyErrorWebExceptionHandler.java[]
----
......@@ -622,7 +622,7 @@ For a more complete picture, you can also subclass `DefaultErrorWebExceptionHand
In some cases, errors handled at the controller or handler function level are not recorded by the <<actuator#actuator.metrics.supported.spring-webflux, metrics infrastructure>>.
Applications can ensure that such exceptions are recorded with the request metrics by setting the handled exception as a request attribute:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/springwebflux/errorhandling/MyExceptionHandlingController.java[]
----
......@@ -637,7 +637,7 @@ The name of the file should be the exact status code or a series mask.
For example, to map `404` to a static HTML file, your directory structure would be as follows:
[source,indent=0,subs="verbatim,quotes,attributes"]
[source,indent=0,subs="verbatim"]
----
src/
+- main/
......@@ -652,7 +652,7 @@ For example, to map `404` to a static HTML file, your directory structure would
To map all `5xx` errors by using a Mustache template, your directory structure would be as follows:
[source,indent=0,subs="verbatim,quotes,attributes"]
[source,indent=0,subs="verbatim"]
----
src/
+- main/
......@@ -700,7 +700,7 @@ Jersey has some native Spring support, so we also provide auto-configuration sup
To get started with Jersey, include the `spring-boot-starter-jersey` as a dependency and then you need one `@Bean` of type `ResourceConfig` in which you register all the endpoints, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/jersey/MyJerseyConfig.java[]
----
......@@ -713,7 +713,7 @@ For more advanced customizations, you can also register an arbitrary number of b
All the registered endpoints should be `@Components` with HTTP resource annotations (`@GET` and others), as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/jersey/MyEndpoint.java[]
----
......@@ -827,7 +827,7 @@ If you need to programmatically configure your embedded servlet container, you c
`WebServerFactoryCustomizer` provides access to the `ConfigurableServletWebServerFactory`, which includes numerous customization setter methods.
The following example shows programmatically setting the port:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/embeddedcontainer/customizing/programmatic/MyWebServerFactoryCustomizer.java[]
----
......@@ -835,7 +835,7 @@ include::{docs-java}/features/developingwebapplications/embeddedcontainer/custom
`TomcatServletWebServerFactory`, `JettyServletWebServerFactory` and `UndertowServletWebServerFactory` are dedicated variants of `ConfigurableServletWebServerFactory` that have additional customization setter methods for Tomcat, Jetty and Undertow respectively.
The following example shows how to customize `TomcatServletWebServerFactory` that provides access to Tomcat-specific configuration options:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/developingwebapplications/embeddedcontainer/customizing/programmatic/MyTomcatWebServerFactoryCustomizer.java[]
----
......
......@@ -10,7 +10,7 @@ See {spring-boot-autoconfigure-module-code}/mail/MailProperties.java[`MailProper
In particular, certain default timeout values are infinite, and you may want to change that to avoid having a thread blocked by an unresponsive mail server, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
mail:
......@@ -22,7 +22,7 @@ In particular, certain default timeout values are infinite, and you may want to
It is also possible to configure a `JavaMailSender` with an existing `Session` from JNDI:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
mail:
......
......@@ -38,7 +38,7 @@ If you have configuration files with both `.properties` and `.yml` format in the
To provide a concrete example, suppose you develop a `@Component` that uses a `name` property, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/MyBean.java[]
----
......@@ -232,7 +232,7 @@ Imports are processed as they are discovered, and are treated as additional docu
For example, you might have the following in your classpath `application.properties` file:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
spring:
application:
......@@ -248,7 +248,7 @@ An import will only be imported once no matter how many times it is declared.
The order an import is defined inside a single document within the properties/yaml file doesn't matter.
For instance, the two examples below produce the same result:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
spring:
config:
......@@ -257,7 +257,7 @@ For instance, the two examples below produce the same result:
property: value
----
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
my:
property: value
......@@ -293,7 +293,7 @@ You can do this by putting an extension hint in square brackets.
For example, suppose you have a `/etc/config/myconfig` file that you wish to import as yaml.
You can import it from your `application.properties` using the following:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
config:
......@@ -333,7 +333,7 @@ The contents of the `username` file would be a config value, and the contents of
To import these properties, you can add the following to your `application.properties` or `application.yaml` file:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
config:
......@@ -365,7 +365,7 @@ For example, given the following volume:
You can use `configtree:/etc/config/*/` as the import location:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
config:
......@@ -382,7 +382,7 @@ Configuration trees can also be used for Docker secrets.
When a Docker swarm service is granted access to a secret, the secret gets mounted into the container.
For example, if a secret named `db.password` is mounted at location `/run/secrets/`, you can make `db.password` available to the Spring environment using the following:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
config:
......@@ -398,7 +398,7 @@ The standard `$\{name}` property-placeholder syntax can be used anywhere within
For example, the following file will set `app.description` to "`MyApp is a Spring Boot application`":
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
app:
name: "MyApp"
......@@ -421,7 +421,7 @@ Three consecutive hyphens represent the end of one document, and the start of th
For example, the following file has two logical documents:
[source,yaml,indent=0]
[source,yaml,indent=0,subs="verbatim"]
----
spring.application.name: MyApp
---
......@@ -431,7 +431,7 @@ For example, the following file has two logical documents:
For `application.properties` files a special `#---` comment is used to mark the document splits:
[source,properties,indent=0]
[source,properties,indent=0,subs="verbatim"]
----
spring.application.name=MyApp
#---
......@@ -472,7 +472,7 @@ The following activation properties are available:
For example, the following specifies that the second document is only active when running on Kubernetes, and only when either the "`prod`" or "`staging`" profiles are active:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
myprop:
always-set
......@@ -511,7 +511,7 @@ NOTE: If you use "`Starters`", SnakeYAML is automatically provided by `spring-bo
YAML documents need to be converted from their hierarchical format to a flat structure that can be used with the Spring `Environment`.
For example, consider the following YAML document:
[source,yaml,indent=0]
[source,yaml,indent=0,subs="verbatim"]
----
environments:
dev:
......@@ -524,7 +524,7 @@ For example, consider the following YAML document:
In order to access these properties from the `Environment`, they would be flattened as follows:
[source,properties,indent=0]
[source,properties,indent=0,subs="verbatim"]
----
environments.dev.url=https://dev.example.com
environments.dev.name=Developer Setup
......@@ -536,7 +536,7 @@ Likewise, YAML lists also need to be flattened.
They are represented as property keys with `[index]` dereferencers.
For example, consider the following YAML:
[source,yaml,indent=0]
[source,yaml,indent=0,subs="verbatim"]
----
my:
servers:
......@@ -546,7 +546,7 @@ For example, consider the following YAML:
The preceding example would be transformed into these properties:
[source,properties,indent=0]
[source,properties,indent=0,subs="verbatim"]
----
my.servers[0]=dev.example.com
my.servers[1]=another.example.com
......@@ -575,7 +575,7 @@ You can also use the `YamlPropertySourceLoader` class if you want to load YAML a
The `RandomValuePropertySource` is useful for injecting random values (for example, into secrets or test cases).
It can produce integers, longs, uuids, or strings, as shown in the following example:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
my:
secret: "${random.value}"
......@@ -614,7 +614,7 @@ TIP: See also the <<features#features.external-config.typesafe-configuration-pro
==== JavaBean properties binding
It is possible to bind a bean declaring standard JavaBean properties as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/javabeanbinding/MyProperties.java[]
----
......@@ -655,7 +655,7 @@ Finally, only standard Java Bean properties are considered and binding on static
==== Constructor binding
The example in the previous section can be rewritten in an immutable fashion as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/constructorbinding/MyProperties.java[]
----
......@@ -669,7 +669,7 @@ Default values can be specified using `@DefaultValue` and the same conversion se
By default, if no properties are bound to `Security`, the `MyProperties` instance will contain a `null` value for `security`.
If you wish you return a non-null instance of `Security` even when no properties are bound to it, you can use an empty `@DefaultValue` annotation to do so:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/constructorbinding/nonnull/MyProperties.java[]
----
......@@ -695,7 +695,7 @@ Sometimes, classes annotated with `@ConfigurationProperties` might not be suitab
In these cases, specify the list of types to process using the `@EnableConfigurationProperties` annotation.
This can be done on any `@Configuration` class, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/enablingannotatedtypes/MyConfiguration.java[]
----
......@@ -705,7 +705,7 @@ Typically, it is added to the main application class that is annotated with `@Sp
By default, scanning will occur from the package of the class that declares the annotation.
If you want to define specific packages to scan, you can do so as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/enablingannotatedtypes/MyApplication.java[]
----
......@@ -728,7 +728,7 @@ If you still want to inject other beans using the constructor, the configuration
==== Using @ConfigurationProperties-annotated types
This style of configuration works particularly well with the `SpringApplication` external YAML configuration, as shown in the following example:
[source,yaml,indent=0]
[source,yaml,indent=0,subs="verbatim"]
----
my:
service:
......@@ -742,7 +742,7 @@ This style of configuration works particularly well with the `SpringApplication`
To work with `@ConfigurationProperties` beans, you can inject them in the same way as any other bean, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/usingannotatedtypes/MyService.java[]
----
......@@ -759,7 +759,7 @@ Doing so can be particularly useful when you want to bind properties to third-pa
To configure a bean from the `Environment` properties, add `@ConfigurationProperties` to its bean registration, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/thirdpartyconfiguration/ThirdPartyConfiguration.java[]
----
......@@ -775,7 +775,7 @@ Common examples where this is useful include dash-separated environment properti
As an example, consider the following `@ConfigurationProperties` class:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/relaxedbinding/MyPersonProperties.java[]
----
......@@ -836,7 +836,7 @@ If the key is not surrounded by `[]`, any characters that are not alpha-numeric,
For example, consider binding the following properties to a `Map<String,String>`:
[source,properties,indent=0,role="primary"]
[source,properties,indent=0,subs="verbatim",role="primary"]
.Properties
----
my.map.[/key1]=value1
......@@ -844,7 +844,7 @@ For example, consider binding the following properties to a `Map<String,String>`
my.map./key3=value3
----
[source,yaml,indent=0,role="secondary"]
[source,yaml,indent=0,subs="verbatim",role="secondary"]
.Yaml
----
my:
......@@ -894,14 +894,14 @@ When lists are configured in more than one place, overriding works by replacing
For example, assume a `MyPojo` object with `name` and `description` attributes that are `null` by default.
The following example exposes a list of `MyPojo` objects from `MyProperties`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/mergingcomplextypes/list/MyProperties.java[]
----
Consider the following configuration:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
my:
list:
......@@ -924,7 +924,7 @@ This configuration _does not_ add a second `MyPojo` instance to the list, and it
When a `List` is specified in multiple profiles, the one with the highest priority (and only that one) is used.
Consider the following example:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
my:
list:
......@@ -949,14 +949,14 @@ For `Map` properties, you can bind with property values drawn from multiple sour
However, for the same property in multiple sources, the one with the highest priority is used.
The following example exposes a `Map<String, MyPojo>` from `MyProperties`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/mergingcomplextypes/map/MyProperties.java[]
----
Consider the following configuration:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
my:
map:
......@@ -1006,7 +1006,7 @@ If you expose a `java.time.Duration` property, the following formats in applicat
Consider the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/conversion/durations/javabeanbinding/MyProperties.java[]
----
......@@ -1029,7 +1029,7 @@ The default unit is milliseconds and can be overridden using `@DurationUnit` as
If you prefer to use constructor binding, the same properties can be exposed, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/conversion/durations/constructorbinding/MyProperties.java[]
----
......@@ -1070,7 +1070,7 @@ If you expose a `DataSize` property, the following formats in application proper
Consider the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/conversion/datasizes/javabeanbinding/MyProperties.java[]
----
......@@ -1091,7 +1091,7 @@ The default unit is bytes and can be overridden using `@DataSizeUnit` as illustr
If you prefer to use constructor binding, the same properties can be exposed, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/conversion/datasizes/constructorbinding/MyProperties.java[]
----
......@@ -1107,7 +1107,7 @@ Spring Boot attempts to validate `@ConfigurationProperties` classes whenever the
You can use JSR-303 `javax.validation` constraint annotations directly on your configuration class.
To do so, ensure that a compliant JSR-303 implementation is on your classpath and then add constraint annotations to your fields, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/validate/MyProperties.java[]
----
......@@ -1117,7 +1117,7 @@ TIP: You can also trigger validation by annotating the `@Bean` method that creat
To ensure that validation is always triggered for nested properties, even when no properties are found, the associated field must be annotated with `@Valid`.
The following example builds on the preceding `MyProperties` example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/externalconfig/typesafeconfigurationproperties/validate/nested/MyProperties.java[]
----
......
......@@ -11,7 +11,7 @@ NOTE: Graceful shutdown with Tomcat requires Tomcat 9.0.33 or later.
To enable graceful shutdown, configure the configprop:server.shutdown[] property, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
shutdown: "graceful"
......@@ -19,7 +19,7 @@ server:
To configure the timeout period, configure the configprop:spring.lifecycle.timeout-per-shutdown-phase[] property, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
lifecycle:
......
......@@ -19,7 +19,7 @@ If your configuration defines an instance name, Spring Boot tries to locate an e
You could also specify the Hazelcast configuration file to use through configuration, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
hazelcast:
......
......@@ -9,7 +9,7 @@ If no properties file is found that matches any of the configured base names, th
The basename of the resource bundle as well as several other attributes can be configured using the `spring.messages` namespace, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
messages:
......
......@@ -41,7 +41,7 @@ Spring Boot tries to auto-configure JMS by looking for a `ConnectionFactory` at
When using JTA, the primary JMS `ConnectionFactory` bean is XA-aware and participates in distributed transactions.
You can inject into your bean without needing to use any `@Qualifier`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/jta/mixingxaandnonxaconnections/primary/MyBean.java[tag=*]
----
......@@ -51,14 +51,14 @@ For example, your JMS processing logic might take longer than the XA timeout.
If you want to use a non-XA `ConnectionFactory`, you can the `nonXaJmsConnectionFactory` bean:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/jta/mixingxaandnonxaconnections/nonxa/MyBean.java[tag=*]
----
For consistency, the `jmsConnectionFactory` bean is also provided by using the bean alias `xaJmsConnectionFactory`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/jta/mixingxaandnonxaconnections/xa/MyBean.java[tag=*]
----
......
......@@ -57,7 +57,7 @@ Also be aware that Spring Boot's own API is {github-issues}10712[not yet annotat
==== runApplication
Spring Boot provides an idiomatic way to run an application with `runApplication<MyApplication>(*args)` as shown in the following example:
[source,kotlin,indent=0]
[source,kotlin,indent=0,subs="verbatim"]
----
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
......@@ -73,7 +73,7 @@ Spring Boot provides an idiomatic way to run an application with `runApplication
This is a drop-in replacement for `SpringApplication.run(MyApplication::class.java, *args)`.
It also allows customization of the application as shown in the following example:
[source,kotlin,indent=0]
[source,kotlin,indent=0,subs="verbatim"]
----
runApplication<MyApplication>(*args) {
setBannerMode(OFF)
......@@ -110,7 +110,7 @@ TIP: `org.jetbrains.kotlinx:kotlinx-coroutines-reactor` dependency is provided b
=== @ConfigurationProperties
`@ConfigurationProperties` when used in combination with <<features#features.external-config.typesafe-configuration-properties.constructor-binding,`@ConstructorBinding`>> supports classes with immutable `val` properties as shown in the following example:
[source,kotlin,indent=0]
[source,kotlin,indent=0,subs="verbatim"]
----
@ConstructorBinding
@ConfigurationProperties("example.kotlin")
......
......@@ -73,7 +73,7 @@ You can set `spring.output.ansi.enabled` to a {spring-boot-module-api}/ansi/Ansi
Color coding is configured by using the `%clr` conversion word.
In its simplest form, the converter colors the output according to the log level, as shown in the following example:
[source,indent=0]
[source,indent=0,subs="verbatim"]
----
%clr(%5p)
----
......@@ -105,7 +105,7 @@ The following table describes the mapping of log levels to colors:
Alternatively, you can specify the color or style that should be used by providing it as an option to the conversion.
For example, to make the text yellow, use the following setting:
[source,indent=0]
[source,indent=0,subs="verbatim"]
----
%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){yellow}
----
......@@ -194,7 +194,7 @@ The `root` logger can be configured by using `logging.level.root`.
The following example shows potential logging settings in `application.properties`:
[source,properties,indent=0,subs="verbatim,quotes,attributes",configprops,role="primary"]
[source,properties,indent=0,subs="verbatim",configprops,role="primary"]
.Properties
----
logging.level.root=warn
......@@ -202,7 +202,7 @@ The following example shows potential logging settings in `application.propertie
logging.level.org.hibernate=error
----
[source,properties,indent=0,subs="verbatim,quotes,attributes",role="secondary"]
[source,properties,indent=0,subs="verbatim",role="secondary"]
.Yaml
----
logging:
......@@ -229,7 +229,7 @@ For example, you might commonly change the logging levels for _all_ Tomcat relat
To help with this, Spring Boot allows you to define logging groups in your Spring `Environment`.
For example, here's how you could define a "`tomcat`" group by adding it to your `application.properties`:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
logging:
group:
......@@ -238,7 +238,7 @@ For example, here's how you could define a "`tomcat`" group by adding it to your
Once defined, you can change the level for all the loggers in the group with a single line:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
logging:
level:
......@@ -271,7 +271,7 @@ You can use the configprop:logging.register-shutdown-hook[] property to disable
Setting it to `false` will disable the registration.
You can set the property in your `application.properties` or `application.yaml` file:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
logging:
register-shutdown-hook: false
......@@ -440,7 +440,7 @@ A profile expression allows for more complicated profile logic to be expressed,
Check the {spring-framework-docs}/core.html#beans-definition-profiles-java[reference guide] for more details.
The following listing shows three sample profiles:
[source,xml,indent=0]
[source,xml,subs="verbatim",indent=0]
----
<springProfile name="staging">
<!-- configuration to be enabled when the "staging" profile is active -->
......@@ -467,7 +467,7 @@ If you need to store the property somewhere other than in `local` scope, you can
If you need a fallback value (in case the property is not set in the `Environment`), you can use the `defaultValue` attribute.
The following example shows how to expose properties for use within Logback:
[source,xml,indent=0]
[source,xml,subs="verbatim",indent=0]
----
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
defaultValue="localhost"/>
......
......@@ -27,7 +27,7 @@ NOTE: If you use `spring-boot-starter-activemq`, the necessary dependencies to c
ActiveMQ configuration is controlled by external configuration properties in `+spring.activemq.*+`.
For example, you might declare the following section in `application.properties`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
activemq:
......@@ -38,7 +38,7 @@ For example, you might declare the following section in `application.properties`
By default, a `CachingConnectionFactory` wraps the native `ConnectionFactory` with sensible settings that you can control by external configuration properties in `+spring.jms.*+`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
jms:
......@@ -48,7 +48,7 @@ By default, a `CachingConnectionFactory` wraps the native `ConnectionFactory` wi
If you'd rather use native pooling, you can do so by adding a dependency to `org.messaginghub:pooled-jms` and configuring the `JmsPoolConnectionFactory` accordingly, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
activemq:
......@@ -77,7 +77,7 @@ Adding `org.apache.activemq:artemis-jms-server` to your application lets you use
ActiveMQ Artemis configuration is controlled by external configuration properties in `+spring.artemis.*+`.
For example, you might declare the following section in `application.properties`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
artemis:
......@@ -92,7 +92,7 @@ These can be specified as a comma-separated list to create them with the default
By default, a `CachingConnectionFactory` wraps the native `ConnectionFactory` with sensible settings that you can control by external configuration properties in `+spring.jms.*+`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
jms:
......@@ -102,7 +102,7 @@ By default, a `CachingConnectionFactory` wraps the native `ConnectionFactory` wi
If you'd rather use native pooling, you can do so by adding a dependency to `org.messaginghub:pooled-jms` and configuring the `JmsPoolConnectionFactory` accordingly, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
artemis:
......@@ -123,7 +123,7 @@ If you are running your application in an application server, Spring Boot tries
By default, the `java:/JmsXA` and `java:/XAConnectionFactory` location are checked.
You can use the configprop:spring.jms.jndi-name[] property if you need to specify an alternative location, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
jms:
......@@ -136,7 +136,7 @@ You can use the configprop:spring.jms.jndi-name[] property if you need to specif
==== Sending a Message
Spring's `JmsTemplate` is auto-configured, and you can autowire it directly into your own beans, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/jms/sending/MyBean.java[]
----
......@@ -161,7 +161,7 @@ This also includes sending response messages that have been performed on the sam
The following component creates a listener endpoint on the `someQueue` destination:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/jms/receiving/MyBean.java[]
----
......@@ -172,14 +172,14 @@ If you need to create more `JmsListenerContainerFactory` instances or if you wan
For instance, the following example exposes another factory that uses a specific `MessageConverter`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/jms/receiving/custom/MyJmsConfiguration.java[]
----
Then you can use the factory in any `@JmsListener`-annotated method as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/jms/receiving/custom/MyBean.java[]
----
......@@ -202,7 +202,7 @@ Spring uses `RabbitMQ` to communicate through the AMQP protocol.
RabbitMQ configuration is controlled by external configuration properties in `+spring.rabbitmq.*+`.
For example, you might declare the following section in `application.properties`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
rabbitmq:
......@@ -214,7 +214,7 @@ For example, you might declare the following section in `application.properties`
Alternatively, you could configure the same connection using the `addresses` attribute:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
rabbitmq:
......@@ -237,7 +237,7 @@ TIP: See https://spring.io/blog/2010/06/14/understanding-amqp-the-protocol-used-
==== Sending a Message
Spring's `AmqpTemplate` and `AmqpAdmin` are auto-configured, and you can autowire them directly into your own beans, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/amqp/sending/MyBean.java[]
----
......@@ -249,7 +249,7 @@ If necessary, any `org.springframework.amqp.core.Queue` that is defined as a bea
To retry operations, you can enable retries on the `AmqpTemplate` (for example, in the event that the broker connection is lost):
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
rabbitmq:
......@@ -274,7 +274,7 @@ If a `MessageConverter` or a `MessageRecoverer` bean is defined, it is automatic
The following sample component creates a listener endpoint on the `someQueue` queue:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/amqp/receiving/MyBean.java[]
----
......@@ -288,14 +288,14 @@ Those two beans are exposed by the auto-configuration.
For instance, the following configuration class exposes another factory that uses a specific `MessageConverter`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/amqp/receiving/custom/MyRabbitConfiguration.java[]
----
Then you can use the factory in any `@RabbitListener`-annotated method, as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/amqp/receiving/custom/MyBean.java[]
----
......@@ -319,7 +319,7 @@ https://kafka.apache.org/[Apache Kafka] is supported by providing auto-configura
Kafka configuration is controlled by external configuration properties in `spring.kafka.*`.
For example, you might declare the following section in `application.properties`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
kafka:
......@@ -339,7 +339,7 @@ See {spring-boot-autoconfigure-module-code}/kafka/KafkaProperties.java[`KafkaPro
==== Sending a Message
Spring's `KafkaTemplate` is auto-configured, and you can autowire it directly in your own beans, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/kafka/sending/MyBean.java[]
----
......@@ -356,7 +356,7 @@ If no `KafkaListenerContainerFactory` has been defined, a default one is automat
The following component creates a listener endpoint on the `someTopic` topic:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/kafka/receiving/MyBean.java[]
----
......@@ -385,7 +385,7 @@ See also <<features#features.messaging.kafka.additional-properties>> for more in
To use the factory bean, wire `StreamsBuilder` into your `@Bean` as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/kafka/streams/MyKafkaStreamsConfiguration.java[]
----
......@@ -408,7 +408,7 @@ Spring Boot auto-configuration supports all HIGH importance properties, some sel
Only a subset of the properties supported by Kafka are available directly through the `KafkaProperties` class.
If you wish to configure the producer or consumer with additional properties that are not directly supported, use the following properties:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
kafka:
......@@ -432,7 +432,7 @@ This sets the common `prop.one` Kafka property to `first` (applies to producers,
You can also configure the Spring Kafka `JsonDeserializer` as follows:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
kafka:
......@@ -445,7 +445,7 @@ You can also configure the Spring Kafka `JsonDeserializer` as follows:
Similarly, you can disable the `JsonSerializer` default behavior of sending type information in headers:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
kafka:
......@@ -470,21 +470,21 @@ There are several ways to do that:
* Provide a system property to map embedded broker addresses into configprop:spring.kafka.bootstrap-servers[] in the test class:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/kafka/embedded/property/MyTest.java[tag=*]
----
* Configure a property name on the `@EmbeddedKafka` annotation:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/messaging/kafka/embedded/annotation/MyTest.java[]
----
* Use a placeholder in configuration properties:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
kafka:
......
......@@ -36,7 +36,7 @@ You can inject an auto-configured `RedisConnectionFactory`, `StringRedisTemplate
By default, the instance tries to connect to a Redis server at `localhost:6379`.
The following listing shows an example of such a bean:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/redis/connecting/MyBean.java[]
----
......@@ -62,7 +62,7 @@ To access MongoDB databases, you can inject an auto-configured `org.springframew
By default, the instance tries to connect to a MongoDB server at `mongodb://localhost/test`.
The following example shows how to connect to a MongoDB database:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/mongodb/connecting/MyBean.java[]
----
......@@ -77,7 +77,7 @@ Each will be called in order with the `MongoClientSettings.Builder` that is used
You can set the configprop:spring.data.mongodb.uri[] property to change the URL and configure additional settings such as the _replica set_, as shown in the following example:
[source,properties,indent=0,configprops]
[source,properties,indent=0,subs="verbatim",configprops]
----
spring.data.mongodb.uri=mongodb://user:secret@mongo1.example.com:12345,mongo2.example.com:23456/test
----
......@@ -85,7 +85,7 @@ You can set the configprop:spring.data.mongodb.uri[] property to change the URL
Alternatively, you can specify connection details using discrete properties.
For example, you might declare the following settings in your `application.properties`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
data:
......@@ -113,7 +113,7 @@ The auto-configuration configures this factory automatically if Netty is availab
{spring-data-mongodb}[Spring Data MongoDB] provides a {spring-data-mongodb-api}/core/MongoTemplate.html[`MongoTemplate`] class that is very similar in its design to Spring's `JdbcTemplate`.
As with `JdbcTemplate`, Spring Boot auto-configures a bean for you to inject the template, as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/mongodb/template/MyBean.java[]
----
......@@ -130,7 +130,7 @@ As with the JPA repositories discussed earlier, the basic principle is that quer
In fact, both Spring Data JPA and Spring Data MongoDB share the same common infrastructure.
You could take the JPA example from earlier and, assuming that `City` is now a MongoDB data class rather than a JPA `@Entity`, it works in the same way, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/mongodb/repositories/CityRepository.java[]
----
......@@ -172,7 +172,7 @@ To access a Neo4j server, you can inject an auto-configured `org.neo4j.driver.Dr
By default, the instance tries to connect to a Neo4j server at `localhost:7687` using the Bolt protocol.
The following example shows how to inject a Neo4j `Driver` that gives you access, amongst other things, to a `Session`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/neo4j/connecting/MyBean.java[]
----
......@@ -180,7 +180,7 @@ include::{docs-java}/features/nosql/neo4j/connecting/MyBean.java[]
You can configure various aspects of the driver using `spring.neo4j.*` properties.
The following example shows how to configure the uri and credentials to use:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
neo4j:
......@@ -204,7 +204,7 @@ For complete details of Spring Data Neo4j, refer to the {spring-data-neo4j-docs}
Spring Data Neo4j shares the common infrastructure with Spring Data JPA as many other Spring Data modules do.
You could take the JPA example from earlier and define `City` as Spring Data Neo4j `@Node` rather than JPA `@Entity` and the repository abstraction works in the same way, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/neo4j/repositories/CityRepository.java[]
----
......@@ -220,7 +220,7 @@ You can customize the locations to look for repositories and entities by using `
In an application using the reactive style, a `ReactiveTransactionManager` is not auto-configured.
To enable transaction management, the following bean must be defined in your configuration:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/neo4j/repositories/MyNeo4jConfiguration.java[]
----
......@@ -241,7 +241,7 @@ You can inject an auto-configured `SolrClient` instance as you would any other S
By default, the instance tries to connect to a server at `http://localhost:8983/solr`.
The following example shows how to inject a Solr bean:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/solr/connecting/MyBean.java[]
----
......@@ -272,7 +272,7 @@ Spring Boot provides support for the "High Level" client, which ships with `org.
If you have this dependency on the classpath, Spring Boot will auto-configure and register a `RestHighLevelClient` bean that by default targets `http://localhost:9200`.
You can further tune how `RestHighLevelClient` is configured, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
elasticsearch:
......@@ -291,7 +291,7 @@ TIP: If your application needs access to a "Low Level" `RestClient`, you can get
Additionally, if `elasticsearch-rest-client-sniffer` is on the classpath, a `Sniffer` is auto-configured to automatically discover nodes from a running Elasticsearch cluster and set them to the `RestHighLevelClient` bean.
You can further tune how `Sniffer` is configured, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
elasticsearch:
......@@ -312,7 +312,7 @@ By default, Spring Boot will auto-configure and register a `ReactiveElasticsearc
bean that targets `http://localhost:9200`.
You can further tune how it is configured, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
data:
......@@ -339,7 +339,7 @@ With this configuration in place, an
`ElasticsearchRestTemplate` can be injected like any other Spring bean,
as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/elasticsearch/connectingusingspringdata/MyBean.java[]
----
......@@ -367,7 +367,7 @@ Same applies to `ReactiveElasticsearchTemplate` and `ReactiveElasticsearchOperat
You can choose to disable the repositories support with the following property:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
data:
......@@ -392,7 +392,7 @@ You can inject an auto-configured `CassandraTemplate` or a Cassandra `CqlSession
The `spring.data.cassandra.*` properties can be used to customize the connection.
Generally, you provide `keyspace-name` and `contact-points` as well the local datacenter name, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
data:
......@@ -404,7 +404,7 @@ Generally, you provide `keyspace-name` and `contact-points` as well the local da
If the port is the same for all your contact points you can use a shortcut and only specify the host names, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
data:
......@@ -432,7 +432,7 @@ NOTE: If you're using `CqlSessionBuilder` to create multiple `CqlSession` beans,
The following code listing shows how to inject a Cassandra bean:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/cassandra/connecting/MyBean.java[]
----
......@@ -464,7 +464,7 @@ You can get a `Cluster` by adding the Couchbase SDK and some configuration.
The `spring.couchbase.*` properties can be used to customize the connection.
Generally, you provide the https://github.com/couchbaselabs/sdk-rfcs/blob/master/rfc/0011-connection-string.md[connection string], username, and password, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
couchbase:
......@@ -476,7 +476,7 @@ Generally, you provide the https://github.com/couchbaselabs/sdk-rfcs/blob/master
It is also possible to customize some of the `ClusterEnvironment` settings.
For instance, the following configuration changes the timeout to use to open a new `Bucket` and enables SSL support:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
couchbase:
......@@ -501,7 +501,7 @@ For complete details of Spring Data Couchbase, refer to the {spring-data-couchba
You can inject an auto-configured `CouchbaseTemplate` instance as you would with any other Spring Bean, provided a `CouchbaseClientFactory` bean is available.
This happens when a `Cluster` is available, as described above, and a bucket name has been specified:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
data:
......@@ -511,7 +511,7 @@ This happens when a `Cluster` is available, as described above, and a bucket nam
The following examples shows how to inject a `CouchbaseTemplate` bean:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/couchbase/repositories/MyBean.java[]
----
......@@ -525,7 +525,7 @@ There are a few beans that you can define in your own configuration to override
To avoid hard-coding those names in your own config, you can reuse `BeanNames` provided by Spring Data Couchbase.
For instance, you can customize the converters to use, as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/couchbase/repositories/MyCouchbaseConfiguration.java[]
----
......@@ -546,7 +546,7 @@ There is a `spring-boot-starter-data-ldap` "`Starter`" for collecting the depend
==== Connecting to an LDAP Server
To connect to an LDAP server, make sure you declare a dependency on the `spring-boot-starter-data-ldap` "`Starter`" or `spring-ldap-core` and then declare the URLs of your server in your application.properties, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
ldap:
......@@ -572,7 +572,7 @@ For complete details of Spring Data LDAP, refer to the https://docs.spring.io/sp
You can also inject an auto-configured `LdapTemplate` instance as you would with any other Spring Bean, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/nosql/ldap/repositories/MyBean.java[]
----
......@@ -584,7 +584,7 @@ include::{docs-java}/features/nosql/ldap/repositories/MyBean.java[]
For testing purposes, Spring Boot supports auto-configuration of an in-memory LDAP server from https://ldap.com/unboundid-ldap-sdk-for-java/[UnboundID].
To configure the server, add a dependency to `com.unboundid:unboundid-ldapsdk` and declare a configprop:spring.ldap.embedded.base-dn[] property, as follows:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
ldap:
......@@ -598,7 +598,7 @@ It is possible to define multiple base-dn values, however, since distinguished n
In yaml files, you can use the yaml list notation. In properties files, you must include the index as part of the property name:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring.ldap.embedded.base-dn:
- dc=spring,dc=io
......@@ -628,7 +628,7 @@ https://www.influxdata.com/[InfluxDB] is an open-source time series database opt
==== Connecting to InfluxDB
Spring Boot auto-configures an `InfluxDB` instance, provided the `influxdb-java` client is on the classpath and the URL of the database is set, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
influx:
......
......@@ -15,7 +15,7 @@ You can use a configprop:spring.profiles.active[] `Environment` property to spec
You can specify the property in any of the ways described earlier in this chapter.
For example, you could include it in your `application.properties`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
profiles:
......@@ -48,7 +48,7 @@ A profile group allows you to define a logical name for a related group of profi
For example, we can create a `production` group that consists of our `proddb` and `prodmq` profiles.
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
spring:
profiles:
......
......@@ -13,7 +13,7 @@ Beans of the following types are automatically picked up and associated with the
By default, an in-memory `JobStore` is used.
However, it is possible to configure a JDBC-based store if a `DataSource` bean is available in your application and if the configprop:spring.quartz.job-store-type[] property is configured accordingly, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
quartz:
......@@ -22,7 +22,7 @@ However, it is possible to configure a JDBC-based store if a `DataSource` bean i
When the JDBC store is used, the schema can be initialized on startup, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
quartz:
......@@ -50,7 +50,7 @@ If you need to customize the task executor, consider implementing `SchedulerFact
Jobs can define setters to inject data map properties.
Regular beans can also be injected in a similar manner, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/quartz/MySampleJob.java[]
----
......@@ -7,7 +7,7 @@ The auto-configured `RestTemplateBuilder` ensures that sensible `HttpMessageConv
The following code shows a typical example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/resttemplate/MyService.java[]
----
......@@ -29,7 +29,7 @@ All such beans are automatically registered with the auto-configured `RestTempla
The following example shows a customizer that configures the use of a proxy for all hosts except `192.168.0.5`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/resttemplate/customization/MyRestTemplateCustomizer.java[]
----
......@@ -38,7 +38,7 @@ Finally, you can also create your own `RestTemplateBuilder` bean.
To prevent switching off the auto-configuration of a `RestTemplateBuilder` and prevent any `RestTemplateCustomizer` beans from being used, make sure to configure your custom instance with a `RestTemplateBuilderConfigurer`.
The following example exposes a `RestTemplateBuilder` with what Spring Boot would auto-configure, except that custom connect and read timeouts are also specified:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/resttemplate/customization/MyRestTemplateBuilderConfiguration.java[]
----
......
......@@ -35,7 +35,7 @@ This depends on the type of application and its configuration.
For WebFlux application (i.e. of type `WebApplicationType.REACTIVE`), the RSocket server will be plugged into the Web Server only if the following properties match:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
rsocket:
......@@ -49,7 +49,7 @@ WARNING: Plugging RSocket into a web server is only supported with Reactor Netty
Alternatively, an RSocket TCP or websocket server is started as an independent, embedded server.
Besides the dependency requirements, the only required configuration is to define a port for that server:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
rsocket:
......@@ -80,7 +80,7 @@ This is done on purpose since this builder is stateful and you shouldn't create
The following code shows a typical example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/rsocket//requester/MyService.java[]
----
......@@ -60,7 +60,7 @@ Spring Boot provides convenience methods that can be used to override access rul
For example, you can customize your security configuration by adding something like:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/security/springwebflux/MyWebFluxSecurityConfiguration.java[]
----
......@@ -81,7 +81,7 @@ The same properties are applicable to both servlet and reactive applications.
You can register multiple OAuth2 clients and providers under the `spring.security.oauth2.client` prefix, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
security:
......@@ -124,7 +124,7 @@ For example, if the `issuer-uri` provided is "https://example.com", then an `Ope
The result is expected to be an `OpenID Provider Configuration Response`.
The following example shows how an OpenID Connect Provider can be configured with the `issuer-uri`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
security:
......@@ -139,7 +139,7 @@ By default, Spring Security's `OAuth2LoginAuthenticationFilter` only processes U
If you want to customize the `redirect-uri` to use a different pattern, you need to provide configuration to process that custom pattern.
For example, for servlet applications, you can add your own `SecurityFilterChain` that resembles the following:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/security/oauth2/client/MyOAuthClientConfiguration.java[]
----
......@@ -159,7 +159,7 @@ Also, if the key for the client registration matches a default supported provide
In other words, the two configurations in the following example use the Google provider:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
security:
......@@ -182,7 +182,7 @@ In other words, the two configurations in the following example use the Google p
If you have `spring-security-oauth2-resource-server` on your classpath, Spring Boot can set up an OAuth2 Resource Server.
For JWT configuration, a JWK Set URI or OIDC Issuer URI needs to be specified, as shown in the following examples:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
security:
......@@ -192,7 +192,7 @@ For JWT configuration, a JWK Set URI or OIDC Issuer URI needs to be specified, a
jwk-set-uri: "https://example.com/oauth2/default/v1/keys"
----
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
security:
......@@ -211,7 +211,7 @@ Alternatively, you can define your own `JwtDecoder` bean for servlet application
In cases where opaque tokens are used instead of JWTs, you can configure the following properties to validate tokens via introspection:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
security:
......@@ -250,7 +250,7 @@ This configuration makes use of the properties under `Saml2RelyingPartyPropertie
A relying party registration represents a paired configuration between an Identity Provider, IDP, and a Service Provider, SP.
You can register multiple relying parties under the `spring.security.saml2.relyingparty` prefix, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
security:
......
......@@ -3,14 +3,14 @@
The `SpringApplication` class provides a convenient way to bootstrap a Spring application that is started from a `main()` method.
In many situations, you can delegate to the static `SpringApplication.run` method, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/springapplication/MyApplication.java[]
----
When your application starts, you should see something similar to the following output:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim,attributes"]
----
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
......@@ -71,7 +71,7 @@ To do so, you need to <<features#features.external-config,enable the `debug` pro
For instance, if you are running your application by using `java -jar`, you can enable the `debug` property as follows:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim"]
----
$ java -jar myproject-0.0.1-SNAPSHOT.jar --debug
----
......@@ -93,7 +93,7 @@ For these reasons, lazy initialization is not enabled by default and it is recom
Lazy initialization can be enabled programmatically using the `lazyInitialization` method on `SpringApplicationBuilder` or the `setLazyInitialization` method on `SpringApplication`.
Alternatively, it can be enabled using the configprop:spring.main.lazy-initialization[] property as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
main:
......@@ -165,7 +165,7 @@ This will initialize the `application.*` banner variables before building the cl
If the `SpringApplication` defaults are not to your taste, you can instead create a local instance and customize it.
For example, to turn off the banner, you could write:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/springapplication/customizingspringapplication/MyApplication.java[]
----
......@@ -186,7 +186,7 @@ If you need to build an `ApplicationContext` hierarchy (multiple contexts with a
The `SpringApplicationBuilder` lets you chain together multiple method calls and includes `parent` and `child` methods that let you create a hierarchy, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/springapplication/fluentbuilderapi/MyApplication.java[tag=*]
----
......@@ -240,14 +240,14 @@ More often, applications will want to listen to state updates or update the stat
For example, we can export the "Readiness" state of the application to a file so that a Kubernetes "exec Probe" can look at this file:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/springapplication/applicationavailability/managing/MyReadinessStateExporter.java[]
----
We can also update the state of the application, when the application breaks and cannot recover:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/springapplication/applicationavailability/managing/MyLocalCacheVerifier.java[]
----
......@@ -332,7 +332,7 @@ TIP: It is often desirable to call `setWebApplicationType(WebApplicationType.NON
If you need to access the application arguments that were passed to `SpringApplication.run(...)`, you can inject a `org.springframework.boot.ApplicationArguments` bean.
The `ApplicationArguments` interface provides access to both the raw `String[]` arguments as well as parsed `option` and `non-option` arguments, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/springapplication/applicationarguments/MyBean.java[]
----
......@@ -353,7 +353,7 @@ NOTE: This contract is well suited for tasks that should run after application s
The `CommandLineRunner` interfaces provides access to application arguments as a string array, whereas the `ApplicationRunner` uses the `ApplicationArguments` interface discussed earlier.
The following example shows a `CommandLineRunner` with a `run` method:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/springapplication/commandlinerunner/MyCommandLineRunner.java[]
----
......@@ -370,7 +370,7 @@ All the standard Spring lifecycle callbacks (such as the `DisposableBean` interf
In addition, beans may implement the `org.springframework.boot.ExitCodeGenerator` interface if they wish to return a specific exit code when `SpringApplication.exit()` is called.
This exit code can then be passed to `System.exit()` to return it as a status code, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/springapplication/applicationexit/MyApplication.java[]
----
......@@ -401,7 +401,7 @@ This data can be collected for profiling purposes, or just to have a better unde
You can choose an `ApplicationStartup` implementation when setting up the `SpringApplication` instance.
For example, to use the `BufferingApplicationStartup`, you could write:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/springapplication/startuptracking/MyApplication.java[]
----
......@@ -410,7 +410,7 @@ The first available implementation, `FlightRecorderApplicationStartup` is provid
It adds Spring-specific startup events to a Java Flight Recorder session and is meant for profiling applications and correlating their Spring context lifecycle with JVM events (such as allocations, GCs, class loading...).
Once configured, you can record data by running the application with the Flight Recorder enabled:
[source,bash,indent=0]
[source,bash,indent=0,subs="verbatim"]
----
$ java -XX:StartFlightRecording:filename=recording.jfr,duration=10s -jar demo.jar
----
......
......@@ -10,7 +10,7 @@ Spring Boot also configures some features that are triggered by the presence of
If `spring-integration-jmx` is also on the classpath, message processing statistics are published over JMX.
If `spring-integration-jdbc` is available, the default database schema can be created on startup, as shown in the following line:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
integration:
......@@ -23,7 +23,7 @@ This infrastructure can handle Spring Integration RSocket channel adapters and `
Spring Boot can also auto-configure an `ClientRSocketConnector` using configuration properties:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
# Connecting to a RSocket server over TCP
spring:
......@@ -34,7 +34,7 @@ Spring Boot can also auto-configure an `ClientRSocketConnector` using configurat
port: 9898
----
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
# Connecting to a RSocket Server over WebSocket
spring:
......
......@@ -21,7 +21,7 @@ If a single Spring Session module is present on the classpath, Spring Boot uses
If you have more than one implementation, you must choose the {spring-boot-autoconfigure-module-code}/session/StoreType.java[`StoreType`] that you wish to use to store the sessions.
For instance, to use JDBC as the back-end store, you can configure your application as follows:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
session:
......@@ -33,7 +33,7 @@ TIP: You can disable Spring Session by setting the `store-type` to `none`.
Each store has specific additional settings.
For instance, it is possible to customize the name of the table for the JDBC store, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
session:
......
......@@ -36,7 +36,7 @@ If you want to make sure that each context has a separate embedded database, you
For example, the typical POM dependencies would be as follows:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -70,7 +70,7 @@ Production database connections can also be auto-configured by using a pooling `
DataSource configuration is controlled by external configuration properties in `+spring.datasource.*+`.
For example, you might declare the following section in `application.properties`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
datasource:
......@@ -95,7 +95,7 @@ Refer to the documentation of the connection pool implementation you are using f
For instance, if you use the {tomcat-docs}/jdbc-pool.html#Common_Attributes[Tomcat connection pool], you could customize many additional settings, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
datasource:
......@@ -145,7 +145,7 @@ If you deploy your Spring Boot application to an Application Server, you might w
The configprop:spring.datasource.jndi-name[] property can be used as an alternative to the configprop:spring.datasource.url[], configprop:spring.datasource.username[], and configprop:spring.datasource.password[] properties to access the `DataSource` from a specific JNDI location.
For example, the following section in `application.properties` shows how you can access a JBoss AS defined `DataSource`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
datasource:
......@@ -158,14 +158,14 @@ For example, the following section in `application.properties` shows how you can
=== Using JdbcTemplate
Spring's `JdbcTemplate` and `NamedParameterJdbcTemplate` classes are auto-configured, and you can `@Autowire` them directly into your own beans, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/sql/jdbctemplate/MyBean.java[]
----
You can customize some properties of the template by using the `spring.jdbc.template.*` properties, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
jdbc:
......@@ -202,7 +202,7 @@ By default, all packages below your main configuration class (the one annotated
Any classes annotated with `@Entity`, `@Embeddable`, or `@MappedSuperclass` are considered.
A typical entity class resembles the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/sql/jpaandspringdata/entityclasses/City.java[]
----
......@@ -225,7 +225,7 @@ If you use auto-configuration, repositories are searched from the package contai
The following example shows a typical Spring Data repository interface definition:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/sql/jpaandspringdata/repositories/CityRepository.java[]
----
......@@ -331,7 +331,7 @@ If you use the `jooq-codegen-maven` plugin and you also use the `spring-boot-sta
You can also use Spring Boot-defined version variables (such as `h2.version`) to declare the plugin's database dependency.
The following listing shows an example:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<plugin>
<groupId>org.jooq</groupId>
......@@ -366,7 +366,7 @@ The fluent API offered by jOOQ is initiated through the `org.jooq.DSLContext` in
Spring Boot auto-configures a `DSLContext` as a Spring Bean and connects it to your application `DataSource`.
To use the `DSLContext`, you can inject it, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/sql/jooq/dslcontext/MyBean.java[tag=!method]
----
......@@ -375,7 +375,7 @@ TIP: The jOOQ manual tends to use a variable named `create` to hold the `DSLCont
You can then use the `DSLContext` to construct your queries, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/sql/jooq/dslcontext/MyBean.java[tag=method]
----
......@@ -409,7 +409,7 @@ Connections are provided via a `ConnectionFactory`, similar to a `DataSource` wi
`ConnectionFactory` configuration is controlled by external configuration properties in `+spring.r2dbc.*+`.
For example, you might declare the following section in `application.properties`:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
r2dbc:
......@@ -428,14 +428,14 @@ TIP: The "`How-to`" section includes a <<howto#howto.data-initialization.using-b
To customize the connections created by a `ConnectionFactory`, i.e., set specific parameters that you do not want (or cannot) configure in your central database configuration, you can use a `ConnectionFactoryOptionsBuilderCustomizer` `@Bean`.
The following example shows how to manually override the database port while the rest of the options is taken from the application configuration:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/sql/r2dbc/MyR2dbcConfiguration.java[]
----
The following examples show how to set some PostgreSQL connection options:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/sql/r2dbc/MyPostgresR2dbcConfiguration.java[]
----
......@@ -451,7 +451,7 @@ Similarly to <<features#features.sql.datasource.embedded,the JDBC support>>, Spr
You need not provide any connection URLs.
You need only include a build dependency to the embedded database that you want to use, as shown in the following example:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>io.r2dbc</groupId>
......@@ -472,7 +472,7 @@ If you want to make sure that each context has a separate embedded database, you
==== Using DatabaseClient
A `DatabaseClient` bean is auto-configured, and you can `@Autowire` it directly into your own beans, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/sql/r2dbc/usingdatabaseclient/MyBean.java[]
----
......@@ -492,7 +492,7 @@ If you use auto-configuration, repositories are searched from the package contai
The following example shows a typical Spring Data repository interface definition:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/sql/r2dbc/repositories/CityRepository.java[]
----
......
......@@ -13,7 +13,7 @@ The auto-configured `TaskExecutorBuilder` allows you to easily create instances
The thread pool uses 8 core threads that can grow and shrink according to the load.
Those default settings can be fine-tuned using the `spring.task.execution` namespace, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
task:
......@@ -30,7 +30,7 @@ Shrinking of the pool is more aggressive as threads are reclaimed when they are
A `ThreadPoolTaskScheduler` can also be auto-configured if need to be associated to scheduled task execution (e.g. `@EnableScheduling`).
The thread pool uses one thread by default and its settings can be fine-tuned using the `spring.task.scheduling` namespace, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
task:
......
......@@ -10,7 +10,7 @@ Most developers use the `spring-boot-starter-test` "`Starter`", which imports bo
If you have tests that use JUnit 4, JUnit 5's vintage engine can be used to run them.
To use the vintage engine, add a dependency on `junit-vintage-engine`, as shown in the following example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>org.junit.vintage</groupId>
......@@ -105,7 +105,7 @@ If you have only Spring WebFlux, we'll detect that and configure a WebFlux-based
If both are present, Spring MVC takes precedence.
If you want to test a reactive web application in this scenario, you must set the configprop:spring.main.web-application-type[] property:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/detectingwebapptype/MyWebFluxTests.java[]
----
......@@ -148,7 +148,7 @@ As we <<features#features.testing.spring-boot-applications.detecting-configurati
When placed on a top-level class, `@TestConfiguration` indicates that classes in `src/test/java` should not be picked up by scanning.
You can then import that class explicitly where it is required, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/excludingconfiguration/MyTests.java[]
----
......@@ -163,7 +163,7 @@ See {spring-boot-module-api}/context/TypeExcludeFilter.html[the Javadoc] for det
If your application expects <<features#features.spring-application.application-arguments,arguments>>, you can
have `@SpringBootTest` inject them using the `args` attribute.
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/usingapplicationarguments/MyApplicationArgumentTests.java[]
----
......@@ -175,7 +175,7 @@ include::{docs-java}/features/testing/springbootapplications/usingapplicationarg
By default, `@SpringBootTest` does not start the server.
If you have web endpoints that you want to test against this mock environment, you can additionally configure {spring-framework-docs}/testing.html#spring-mvc-test-framework[`MockMvc`] as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/withmockenvironment/MyMockMvcTests.java[]
----
......@@ -184,7 +184,7 @@ TIP: If you want to focus only on the web layer and not start a complete `Applic
Alternatively, you can configure a {spring-framework-docs}/testing.html#webtestclient-tests[`WebTestClient`] as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/withmockenvironment/MyMockWebTestClientTests.java[]
----
......@@ -209,7 +209,7 @@ If you use `@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)`, an avai
The `@LocalServerPort` annotation can be used to <<howto#howto.webserver.discover-port,inject the actual port used>> into your test.
For convenience, tests that need to make REST calls to the started server can additionally `@Autowire` a {spring-framework-docs}/testing.html#webtestclient-tests[`WebTestClient`], which resolves relative links to the running server and comes with a dedicated API for verifying responses, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/withrunningserver/MyRandomPortWebTestClientTests.java[]
----
......@@ -217,7 +217,7 @@ include::{docs-java}/features/testing/springbootapplications/withrunningserver/M
This setup requires `spring-webflux` on the classpath.
If you can't or won't add webflux, Spring Boot also provides a `TestRestTemplate` facility:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/withrunningserver/MyRandomPortTestRestTemplateTests.java[]
----
......@@ -236,7 +236,7 @@ Any such beans are called with the `WebTestClient.Builder` that is used to creat
As the test context framework caches context, JMX is disabled by default to prevent identical components to register on the same domain.
If such test needs access to an `MBeanServer`, consider marking it dirty as well:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/jmx/MyJmxTests.java[]
----
......@@ -268,7 +268,7 @@ Mock beans are automatically reset after each test method.
If your test uses one of Spring Boot's test annotations (such as `@SpringBootTest`), this feature is automatically enabled.
To use this feature with a different arrangement, listeners must be explicitly added, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/mockingbeans/listener/MyTests.java[]
----
......@@ -277,7 +277,7 @@ include::{docs-java}/features/testing/springbootapplications/mockingbeans/listen
The following example replaces an existing `RemoteService` bean with a mock implementation:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/mockingbeans/bean/MyTests.java[]
----
......@@ -343,7 +343,7 @@ The `JacksonTester`, `GsonTester`, `JsonbTester`, and `BasicJsonTester` classes
Any helper fields on the test class can be `@Autowired` when using `@JsonTest`.
The following example shows a test class for Jackson:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/jsontests/MyJsonTests.java[]
----
......@@ -355,7 +355,7 @@ If you're using Spring Boot's AssertJ-based helpers to assert on a number value
Instead, you can use AssertJ's `satisfies` to assert that the value matches the given condition.
For instance, the following example asserts that the actual number is a float value close to `0.15` within an offset of `0.01`.
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/jsontests/MyJsonAssertJTests.java[tag=*]
----
......@@ -381,7 +381,7 @@ Mock MVC offers a powerful way to quickly test MVC controllers without needing t
TIP: You can also auto-configure `MockMvc` in a non-`@WebMvcTest` (such as `@SpringBootTest`) by annotating it with `@AutoConfigureMockMvc`.
The following example uses `MockMvc`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/springmvctests/MyControllerTests.java[]
----
......@@ -391,7 +391,7 @@ TIP: If you need to configure elements of the auto-configuration (for example, w
If you use HtmlUnit or Selenium, auto-configuration also provides an HtmlUnit `WebClient` bean and/or a Selenium `WebDriver` bean.
The following example uses HtmlUnit:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/springmvctests/MyHtmlUnitTests.java[]
----
......@@ -428,7 +428,7 @@ Often, `@WebFluxTest` is limited to a single controller and used in combination
TIP: You can also auto-configure `WebTestClient` in a non-`@WebFluxTest` (such as `@SpringBootTest`) by annotating it with `@AutoConfigureWebTestClient`.
The following example shows a class that uses both `@WebFluxTest` and a `WebTestClient`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/springwebfluxtests/MyControllerTests.java[]
----
......@@ -457,7 +457,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@DataCassand
The following example shows a typical setup for using Cassandra tests in Spring Boot:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringdatacassandra/MyDataCassandraTests.java[]
----
......@@ -481,7 +481,7 @@ By default, data JPA tests are transactional and roll back at the end of each te
See the {spring-framework-docs}/testing.html#testcontext-tx-enabling-transactions[relevant section] in the Spring Framework Reference Documentation for more details.
If that is not what you want, you can disable transaction management for a test or for the whole class as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringdatajpa/MyNonTransactionalTests.java[]
----
......@@ -491,7 +491,7 @@ If you want to use `TestEntityManager` outside of `@DataJpaTest` instances, you
A `JdbcTemplate` is also available if you need that.
The following example shows the `@DataJpaTest` annotation in use:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringdatajpa/withoutdb/MyRepositoryTests.java[]
----
......@@ -499,7 +499,7 @@ include::{docs-java}/features/testing/springbootapplications/autoconfiguredsprin
In-memory embedded databases generally work well for tests, since they are fast and do not require any installation.
If, however, you prefer to run tests against a real database you can use the `@AutoConfigureTestDatabase` annotation, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringdatajpa/withdb/MyRepositoryTests.java[]
----
......@@ -519,7 +519,7 @@ By default, JDBC tests are transactional and roll back at the end of each test.
See the {spring-framework-docs}/testing.html#testcontext-tx-enabling-transactions[relevant section] in the Spring Framework Reference Documentation for more details.
If that is not what you want, you can disable transaction management for a test or for the whole class, as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredjdbc/MyTransactionalTests.java[]
----
......@@ -561,7 +561,7 @@ TIP: A list of the auto-configurations that are enabled by `@JooqTest` can be <<
`@JooqTest` configures a `DSLContext`.
The following example shows the `@JooqTest` annotation in use:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredjooq/MyJooqTests.java[]
----
......@@ -583,7 +583,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@DataMongoTe
The following class shows the `@DataMongoTest` annotation in use:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringdatamongodb/withoutdb/MyDataMongoDbTests.java[]
----
......@@ -591,7 +591,7 @@ include::{docs-java}/features/testing/springbootapplications/autoconfiguredsprin
In-memory embedded MongoDB generally works well for tests, since it is fast and does not require any developer installation.
If, however, you prefer to run tests against a real MongoDB server, you should exclude the embedded MongoDB auto-configuration, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringdatamongodb/withdb/MyDataMongoDbTests.java[]
----
......@@ -610,7 +610,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@DataNeo4jTe
The following example shows a typical setup for using Neo4J tests in Spring Boot:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringdataneo4j/propagation/MyDataNeo4jTests.java[]
----
......@@ -619,7 +619,7 @@ By default, Data Neo4j tests are transactional and roll back at the end of each
See the {spring-framework-docs}/testing.html#testcontext-tx-enabling-transactions[relevant section] in the Spring Framework Reference Documentation for more details.
If that is not what you want, you can disable transaction management for a test or for the whole class, as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringdataneo4j/nopropagation/MyDataNeo4jTests.java[]
----
......@@ -641,7 +641,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@DataRedisTe
The following example shows the `@DataRedisTest` annotation in use:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringdataredis/MyDataRedisTests.java[]
----
......@@ -660,7 +660,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@DataLdapTes
The following example shows the `@DataLdapTest` annotation in use:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringdataldap/inmemory/MyDataLdapTests.java[]
----
......@@ -668,7 +668,7 @@ include::{docs-java}/features/testing/springbootapplications/autoconfiguredsprin
In-memory embedded LDAP generally works well for tests, since it is fast and does not require any developer installation.
If, however, you prefer to run tests against a real LDAP server, you should exclude the embedded LDAP auto-configuration, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringdataldap/server/MyDataLdapTests.java[]
----
......@@ -686,7 +686,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@RestClientT
The specific beans that you want to test should be specified by using the `value` or `components` attribute of `@RestClientTest`, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredrestclient/MyRestClientTests.java[]
----
......@@ -708,14 +708,14 @@ It can also be used to configure the host, scheme, and port that appears in any
`@AutoConfigureRestDocs` customizes the `MockMvc` bean to use Spring REST Docs when testing Servlet-based web applications.
You can inject it by using `@Autowired` and use it in your tests as you normally would when using Mock MVC and Spring REST Docs, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringrestdocs/withmockmvc/MyUserDocumentationTests.java[]
----
If you require more control over Spring REST Docs configuration than offered by the attributes of `@AutoConfigureRestDocs`, you can use a `RestDocsMockMvcConfigurationCustomizer` bean, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringrestdocs/withmockmvc/MyRestDocsConfiguration.java[]
----
......@@ -724,7 +724,7 @@ If you want to make use of Spring REST Docs support for a parameterized output d
The auto-configuration calls `alwaysDo` with this result handler, thereby causing each `MockMvc` call to automatically generate the default snippets.
The following example shows a `RestDocumentationResultHandler` being defined:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringrestdocs/withmockmvc/MyResultHandlerConfiguration.java[]
----
......@@ -736,14 +736,14 @@ include::{docs-java}/features/testing/springbootapplications/autoconfiguredsprin
`@AutoConfigureRestDocs` can also be used with `WebTestClient` when testing reactive web applications.
You can inject it by using `@Autowired` and use it in your tests as you normally would when using `@WebFluxTest` and Spring REST Docs, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringrestdocs/withwebtestclient/MyUsersDocumentationTests.java[]
----
If you require more control over Spring REST Docs configuration than offered by the attributes of `@AutoConfigureRestDocs`, you can use a `RestDocsWebTestClientConfigurationCustomizer` bean, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringrestdocs/withwebtestclient/MyRestDocsConfiguration.java[]
----
......@@ -755,14 +755,14 @@ include::{docs-java}/features/testing/springbootapplications/autoconfiguredsprin
`@AutoConfigureRestDocs` makes a `RequestSpecification` bean, preconfigured to use Spring REST Docs, available to your tests.
You can inject it by using `@Autowired` and use it in your tests as you normally would when using REST Assured and Spring REST Docs, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringrestdocs/withrestassured/MyUserDocumentationTests.java[]
----
If you require more control over Spring REST Docs configuration than offered by the attributes of `@AutoConfigureRestDocs`, a `RestDocsRestAssuredConfigurationCustomizer` bean can be used, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredspringrestdocs/withrestassured/MyRestDocsConfiguration.java[]
----
......@@ -780,7 +780,7 @@ TIP: A list of the auto-configuration settings that are enabled by `@WebServiceC
The following example shows the `@WebServiceClientTest` annotation in use:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/autoconfiguredwebservices/MyWebServiceClientTests.java[]
----
......@@ -792,7 +792,7 @@ include::{docs-java}/features/testing/springbootapplications/autoconfiguredwebse
Each slice provides one or more `@AutoConfigure...` annotations that namely defines the auto-configurations that should be included as part of a slice.
Additional auto-configurations can be added on a test-by-test basis by creating a custom `@AutoConfigure...` annotation or by adding `@ImportAutoConfiguration` to the test as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/additionalautoconfigurationandslicing/MyJdbcTests.java[]
----
......@@ -819,7 +819,7 @@ It then becomes important not to litter the application's main class with config
Assume that you are using Spring Batch and you rely on the auto-configuration for it.
You could define your `@SpringBootApplication` as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/userconfigurationandslicing/MyApplication.java[]
----
......@@ -827,7 +827,7 @@ include::{docs-java}/features/testing/springbootapplications/userconfigurationan
Because this class is the source configuration for the test, any slice test actually tries to start Spring Batch, which is definitely not what you want to do.
A recommended approach is to move that area-specific configuration to a separate `@Configuration` class at the same level as your application, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/userconfigurationandslicing/MyBatchConfiguration.java[]
----
......@@ -838,14 +838,14 @@ The latter approach lets you enable it in one of your tests, if necessary, with
Test slices exclude `@Configuration` classes from scanning.
For example, for a `@WebMvcTest`, the following configuration will not include the given `WebMvcConfigurer` bean in the application context loaded by the test slice:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/userconfigurationandslicing/MyWebConfiguration.java[]
----
The configuration below will, however, cause the custom `WebMvcConfigurer` to be loaded by the test slice.
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/userconfigurationandslicing/MyWebMvcConfigurer.java[]
----
......@@ -854,7 +854,7 @@ Another source of confusion is classpath scanning.
Assume that, while you structured your code in a sensible way, you need to scan an additional package.
Your application may resemble the following code:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/springbootapplications/userconfigurationandslicing/scan/MyApplication.java[]
----
......@@ -890,7 +890,7 @@ A few test utility classes that are generally useful when testing your applicati
`ConfigDataApplicationContextInitializer` is an `ApplicationContextInitializer` that you can apply to your tests to load Spring Boot `application.properties` files.
You can use it when you do not need the full set of features provided by `@SpringBootTest`, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/utilities/configdataapplicationcontextinitializer/MyConfigFileTests.java[]
----
......@@ -906,7 +906,7 @@ For `@Value` support, you need to either additionally configure a `PropertySourc
`TestPropertyValues` lets you quickly add properties to a `ConfigurableEnvironment` or `ConfigurableApplicationContext`.
You can call it with `key=value` strings, as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/utilities/testpropertyvalues/MyEnvironmentTests.java[]
----
......@@ -918,7 +918,7 @@ include::{docs-java}/features/testing/utilities/testpropertyvalues/MyEnvironment
`OutputCapture` is a JUnit `Extension` that you can use to capture `System.out` and `System.err` output.
To use add `@ExtendWith(OutputCaptureExtension.class)` and inject `CapturedOutput` as an argument to your test class constructor or test method as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/utilities/outputcapture/MyOutputCaptureTests.java[]
----
......@@ -943,7 +943,7 @@ If you do use Apache's HTTP client, some additional test-friendly features are e
`TestRestTemplate` can be instantiated directly in your integration tests, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/utilities/testresttemplate/MyTests.java[]
----
......@@ -952,7 +952,7 @@ Alternatively, if you use the `@SpringBootTest` annotation with `WebEnvironment.
If necessary, additional customizations can be applied through the `RestTemplateBuilder` bean.
Any URLs that do not specify a host and port automatically connect to the embedded server, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/testing/utilities/testresttemplate/MySpringBootTests.java[]
----
......@@ -6,7 +6,7 @@ Target classes with such annotated methods need to be annotated with the `@Valid
For instance, the following service triggers the validation of the first argument, making sure its size is between 8 and 10:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/validation/MyBean.java[]
----
......@@ -9,7 +9,7 @@ Spring Boot is configuring that builder to share HTTP resources, reflect codecs
The following code shows a typical example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/webclient/MyService.java[]
----
......
......@@ -8,7 +8,7 @@ The {spring-webservices-docs}[Spring Web Services features] can be easily access
To do so, configure their location, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
webservices:
......@@ -25,7 +25,7 @@ It does, however, auto-configure a `WebServiceTemplateBuilder`, which can be use
The following code shows a typical example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/webservices/template/MyService.java[]
----
......@@ -33,7 +33,7 @@ include::{docs-java}/features/webservices/template/MyService.java[]
By default, `WebServiceTemplateBuilder` detects a suitable HTTP-based `WebServiceMessageSender` using the available HTTP client libraries on the classpath.
You can also customize read and connection timeouts as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/features/webservices/template/MyWebServiceTemplateConfiguration.java[]
----
......@@ -7,7 +7,7 @@ Spring Framework provides {spring-framework-docs}/web.html#websocket[rich WebSoc
WebSocket support is also available for {spring-framework-docs}/web-reactive.html#webflux-websocket[reactive web applications] and requires to include the WebSocket API alongside `spring-boot-starter-webflux`:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>javax.websocket</groupId>
......
......@@ -42,7 +42,7 @@ We need to start by creating a Maven `pom.xml` file.
The `pom.xml` is the recipe that is used to build your project.
Open your favorite text editor and add the following:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim,attributes"]
----
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
......@@ -130,7 +130,7 @@ The `mvn dependency:tree` command prints a tree representation of your project d
You can see that `spring-boot-starter-parent` provides no dependencies by itself.
To add the necessary dependencies, edit your `pom.xml` and add the `spring-boot-starter-web` dependency immediately below the `parent` section:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependencies>
<dependency>
......@@ -149,7 +149,7 @@ If you run `mvn dependency:tree` again, you see that there are now a number of a
To finish our application, we need to create a single Java file.
By default, Maven compiles sources from `src/main/java`, so you need to create that directory structure and then add a file named `src/main/java/MyApplication.java` to contain the following code:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/gettingstarted/firstapplication/code/MyApplication.java[]
----
......@@ -208,7 +208,7 @@ Since you used the `spring-boot-starter-parent` POM, you have a useful `run` goa
Type `mvn spring-boot:run` from the root project directory to start the application.
You should see output similar to the following:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim,attributes"]
----
$ mvn spring-boot:run
......@@ -257,7 +257,7 @@ Spring Boot takes a <<executable-jar#executable-jar, different approach>> and le
To create an executable jar, we need to add the `spring-boot-maven-plugin` to our `pom.xml`.
To do so, insert the following lines just below the `dependencies` section:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<build>
<plugins>
......@@ -275,7 +275,7 @@ See the {spring-boot-maven-plugin-docs}#getting-started[plugin documentation] fo
Save your `pom.xml` and run `mvn package` from the command line, as follows:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim,attributes"]
----
$ mvn package
......@@ -308,7 +308,7 @@ This is the original jar file that Maven created before it was repackaged by Spr
To run that application, use the `java -jar` command, as follows:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim,attributes"]
----
$ java -jar target/myproject-0.0.1-SNAPSHOT.jar
......
......@@ -93,7 +93,7 @@ Alternatively, you can use `java -jar` with the `.jar` file (the script helps yo
SDKMAN! (The Software Development Kit Manager) can be used for managing multiple versions of various binary SDKs, including Groovy and the Spring Boot CLI.
Get SDKMAN! from https://sdkman.io and install Spring Boot by using the following commands:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim,attributes"]
----
$ sdk install springboot
$ spring --version
......@@ -102,7 +102,7 @@ Get SDKMAN! from https://sdkman.io and install Spring Boot by using the followin
If you develop features for the CLI and want access to the version you built, use the following commands:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim,attributes"]
----
$ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-{spring-boot-version}-bin/spring-{spring-boot-version}/
$ sdk default springboot dev
......@@ -115,7 +115,7 @@ It points at your target build location, so every time you rebuild Spring Boot,
You can see it by running the following command:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim,attributes"]
----
$ sdk ls springboot
......@@ -202,7 +202,7 @@ In that case, run `scoop update` and try again.
You can use the following web application to test your installation.
To start, create a file called `app.groovy`, as follows:
[source,groovy,indent=0,subs="verbatim,quotes,attributes"]
[source,groovy,indent=0,pending-extract=true,subs="verbatim"]
----
@RestController
class ThisWillActuallyRun {
......@@ -244,7 +244,7 @@ When upgrading to a new feature release, some properties may have been renamed o
Spring Boot provides a way to analyze your application's environment and print diagnostics at startup, but also temporarily migrate properties at runtime for you.
To enable that feature, add the following dependency to your project:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -66,7 +66,7 @@ To export these, you'll need to convert these states to some set of numbers so t
The following example shows one way to write such an exporter:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/actuator/maphealthindicatorstometrics/MyHealthMetricsExportConfiguration.java[]
----
......@@ -17,7 +17,7 @@ If, for whatever reason, you cannot handle the exception, return `null` to give
`FailureAnalyzer` implementations must be registered in `META-INF/spring.factories`.
The following example registers `ProjectConstraintViolationFailureAnalyzer`:
[source,properties,indent=0]
[source,properties,indent=0,subs="verbatim"]
----
org.springframework.boot.diagnostics.FailureAnalyzer=\
com.example.ProjectConstraintViolationFailureAnalyzer
......@@ -78,7 +78,7 @@ Each implementation should be registered in `META-INF/spring.factories`, as show
The implementation can load arbitrary files and add them to the `Environment`.
For instance, the following example loads a YAML configuration file from the classpath:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/application/customizetheenvironmentorapplicationcontext/MyEnvironmentPostProcessor.java[]
----
......
......@@ -35,7 +35,7 @@ Spring Boot converts any command line argument starting with `--` to a property
This should not be used to pass arguments to batch jobs.
To specify batch arguments on the command line, use the regular format (i.e. without `--`), as shown in the following example:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim"]
----
$ java -jar myapp.jar someParameter=someValue anotherParameter=anotherValue
----
......@@ -43,7 +43,7 @@ To specify batch arguments on the command line, use the regular format (i.e. wit
If you specify a property of the `Environment` on the command line, it is ignored by the job.
Consider the following command:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim"]
----
$ java -jar myapp.jar --server.port=7070 someParameter=someValue
----
......
......@@ -13,7 +13,7 @@ When such a file is present, Spring Boot auto-configures a `BuildProperties` bea
To generate build information with Maven, add an execution for the `build-info` goal, as shown in the following example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim,attributes"]
----
<build>
<plugins>
......@@ -37,7 +37,7 @@ TIP: See the {spring-boot-maven-plugin-docs}#goals-build-info[Spring Boot Maven
The following example does the same with Gradle:
[source,gradle,indent=0,subs="verbatim,attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
springBoot {
buildInfo()
......@@ -55,7 +55,7 @@ Both Maven and Gradle allow generating a `git.properties` file containing inform
For Maven users, the `spring-boot-starter-parent` POM includes a pre-configured plugin to generate a `git.properties` file.
To use it, add the following declaration to your POM:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<build>
<plugins>
......@@ -69,7 +69,7 @@ To use it, add the following declaration to your POM:
Gradle users can achieve the same result by using the https://plugins.gradle.org/plugin/com.gorylenko.gradle-git-properties[`gradle-git-properties`] plugin, as shown in the following example:
[source,gradle,indent=0]
[source,gradle,indent=0,subs="verbatim"]
----
plugins {
id "com.gorylenko.gradle-git-properties" version "2.2.4"
......@@ -103,7 +103,7 @@ To override dependency versions in Gradle, see {spring-boot-gradle-plugin-docs}#
The `spring-boot-maven-plugin` can be used to create an executable "`fat`" JAR.
If you use the `spring-boot-starter-parent` POM, you can declare the plugin and your jars are repackaged as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<build>
<plugins>
......@@ -118,7 +118,7 @@ If you use the `spring-boot-starter-parent` POM, you can declare the plugin and
If you do not use the parent POM, you can still use the plugin.
However, you must additionally add an `<executions>` section, as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<build>
<plugins>
......@@ -157,7 +157,7 @@ This classifier is applied to the name of the executable archive, leaving the de
To configure a classifier of `exec` in Maven, you can use the following configuration:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<build>
<plugins>
......@@ -187,7 +187,7 @@ WARNING: Care should be taken to ensure that your operating system is configured
For example, to indicate that JRuby should be flagged for unpacking by using the Maven Plugin, you would add the following configuration:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<build>
<plugins>
......@@ -216,7 +216,7 @@ For example, the `application.yml` configuration file might be excluded from the
In Maven, the executable jar must be the main artifact and you can add a classified jar for the library, as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<build>
<plugins>
......@@ -272,7 +272,7 @@ To make it executable, you can either use the `spring-boot-antlib` module or you
The following example shows how to build an executable archive with Ant:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<target name="build" depends="compile">
<jar destfile="target/${ant.project.name}-${spring-boot.version}.jar" compress="false">
......
......@@ -13,14 +13,14 @@ If you need to externalize some settings, you can bind your `DataSource` to the
The following example shows how to define a data source in a bean:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/configurecustomdatasource/custom/MyDataSourceConfiguration.java[]
----
The following example shows how to define a data source by setting properties:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
app:
datasource:
......@@ -37,7 +37,7 @@ It also auto-detects the driver based on the JDBC URL.
The following example shows how to create a data source by using a `DataSourceBuilder`:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/configurecustomdatasource/builder/MyDataSourceConfiguration.java[]
----
......@@ -48,7 +48,7 @@ Check the implementation that is going to be used at runtime for more details.
The following example shows how to define a JDBC data source by setting properties:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
app:
datasource:
......@@ -63,7 +63,7 @@ Because the actual type of the connection pool is not exposed, no keys are gener
Also, if you happen to have Hikari on the classpath, this basic setup does not work, because Hikari has no `url` property (but does have a `jdbcUrl` property).
In that case, you must rewrite your configuration as follows:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
app:
datasource:
......@@ -78,7 +78,7 @@ You cannot change the implementation at runtime, but the list of options will be
The following example shows how create a `HikariDataSource` with `DataSourceBuilder`:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/configurecustomdatasource/simple/MyDataSourceConfiguration.java[]
----
......@@ -88,7 +88,7 @@ You can easily initialize a `DataSourceBuilder` from the state of any `DataSourc
However, that would split your configuration into two namespaces: `url`, `username`, `password`, `type`, and `driver` on `spring.datasource` and the rest on your custom namespace (`app.datasource`).
To avoid that, you can redefine a custom `DataSourceProperties` on your custom namespace, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/configurecustomdatasource/configurable/MyDataSourceConfiguration.java[]
----
......@@ -96,7 +96,7 @@ include::{docs-java}/howto/dataaccess/configurecustomdatasource/configurable/MyD
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.
Because `DataSourceProperties` is taking care of the `url`/`jdbcUrl` translation for you, you can configure it as follows:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
app:
datasource:
......@@ -125,7 +125,7 @@ You must, however, mark one of the `DataSource` instances as `@Primary`, because
If you create your own `DataSource`, the auto-configuration backs off.
In the following example, we provide the _exact_ same feature set as the auto-configuration provides on the primary data source:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/configuretwodatasources/MyDataSourcesConfiguration.java[]
----
......@@ -135,7 +135,7 @@ TIP: `firstDataSourceProperties` has to be flagged as `@Primary` so that the dat
Both data sources are also bound for advanced customizations.
For instance, you could configure them as follows:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
app:
datasource:
......@@ -155,7 +155,7 @@ For instance, you could configure them as follows:
You can apply the same concept to the secondary `DataSource` as well, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/configuretwodatasources/MyCompleteDataSourcesConfiguration.java[]
----
......@@ -186,7 +186,7 @@ For more about Spring Data, see the {spring-data}[Spring Data project page].
Spring Boot tries to guess the location of your `@Entity` definitions, based on the `@EnableAutoConfiguration` it finds.
To get more control, you can use the `@EntityScan` annotation, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/MyApplication.java[]
----
......@@ -207,7 +207,7 @@ If you prefer to set the dialect yourself, set the configprop:spring.jpa.databas
The most common options to set are shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
jpa:
......@@ -242,21 +242,21 @@ Alternatively, if `ImplicitNamingStrategy` or `PhysicalNamingStrategy` beans are
By default, Spring Boot configures the physical naming strategy with `SpringPhysicalNamingStrategy`.
This implementation provides the same table structure as Hibernate 4: all dots are replaced by underscores and camel casing is replaced by underscores as well. Additionally, by default, all table names are generated in lower case. For example, a `TelephoneNumber` entity is mapped to the `telephone_number` table. If your schema requires mixed-case identifiers, define a custom `SpringPhysicalNamingStrategy` bean, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/configurehibernatenamingstrategy/spring/MyHibernateConfiguration.java[]
----
If you prefer to use Hibernate 5's default instead, set the following property:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,properties,subs="verbatim"]
----
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
----
Alternatively, you can configure the following bean:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/configurehibernatenamingstrategy/standard/MyHibernateConfiguration.java[]
----
......@@ -273,7 +273,7 @@ Rather than configuring Hibernate to lookup the cache provider again, it is bett
To do this with JCache, first make sure that `org.hibernate:hibernate-jcache` is available on the classpath.
Then, add a `HibernatePropertiesCustomizer` bean as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/configurehibernatesecondlevelcaching/MyHibernateSecondLevelCacheConfiguration.java[]
----
......@@ -306,7 +306,7 @@ If you need to use JPA against multiple data sources, you likely need one `Entit
The `LocalContainerEntityManagerFactoryBean` from Spring ORM allows you to configure an `EntityManagerFactory` for your needs.
You can also reuse `JpaProperties` to bind settings for each `EntityManagerFactory`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/MyEntityManagerFactoryConfiguration.java[]
----
......@@ -325,12 +325,12 @@ Alternatively, you might be able to use a JTA transaction manager that spans bot
If you use Spring Data, you need to configure `@EnableJpaRepositories` accordingly, as shown in the following examples:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/OrderConfiguration.java[]
----
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/CustomerConfiguration.java[]
----
......@@ -390,7 +390,7 @@ For example, when Flyway is auto-configured, Hibernate is configured to depend u
If you are configuring a component yourself, you can use an `EntityManagerFactoryDependsOnPostProcessor` subclass as a convenient way of setting up the necessary dependencies.
For example, if you use Hibernate Search with Elasticsearch as its index manager, any `EntityManagerFactory` beans must be configured to depend on the `elasticsearchClient` bean, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/dataaccess/configureacomponentthatisusedbyjpa/ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java[]
----
......
......@@ -66,7 +66,7 @@ Spring Boot can detect your database type and execute those scripts on startup.
If you use an embedded database, this happens by default.
You can also enable it for any database type, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
batch:
......@@ -93,7 +93,7 @@ By default, they are in a directory called `classpath:db/migration`, but you can
This is a comma-separated list of one or more `classpath:` or `filesystem:` locations.
For example, the following configuration would search for scripts in both the default classpath location and the `/opt/migration` directory:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
flyway:
......@@ -103,7 +103,7 @@ For example, the following configuration would search for scripts in both the de
You can also add a special `\{vendor}` placeholder to use vendor-specific scripts.
Assume the following:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
flyway:
......@@ -141,7 +141,7 @@ For example, you can place test-specific migrations in `src/test/resources` and
Also, you can use profile-specific configuration to customize `spring.flyway.locations` so that certain migrations run only when a particular profile is active.
For example, in `application-dev.properties`, you might specify the following setting:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
flyway:
......
......@@ -20,7 +20,7 @@ When Reactor Netty is on the classpath a Reactor Netty-based `WebClient` is auto
To customize the client's handling of network connections, provide a `ClientHttpConnector` bean.
The following example configures a 60 second connect timeout and adds a `ReadTimeoutHandler`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/httpclients/webclientreactornettycustomization/MyReactorNettyClientConfiguration.java[]
----
......
......@@ -6,7 +6,7 @@ Spring Boot manages both of these dependencies so you can switch to Jedis withou
The following example shows how to do so in Maven:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -26,7 +26,7 @@ The following example shows how to do so in Maven:
The following example shows how to do so in Gradle:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
dependencies {
implementation('org.springframework.boot:spring-boot-starter-data-redis') {
......
......@@ -11,7 +11,7 @@ This prevents Jersey from committing the response before Spring Security has had
The `jersey.config.server.response.setStatusOverSendError` property must be set to `true` on the application's `ResourceConfig` bean, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/jersey/springsecurity/JerseySetStatusOverSendErrorConfig.java[]
----
......@@ -24,7 +24,7 @@ To use Jersey alongside another web framework, such as Spring MVC, it should be
First, configure Jersey to use a Filter rather than a Servlet by configuring the configprop:spring.jersey.type[] application property with a value of `filter`.
Second, configure your `ResourceConfig` to forward requests that would have resulted in a 404, as shown in the following example.
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/jersey/alongsideanotherwebframework/JerseyConfig.java[]
----
......@@ -6,7 +6,7 @@ The recommended way to do that is through the starters, which all depend on `spr
For a web application, you need only `spring-boot-starter-web`, since it depends transitively on the logging starter.
If you use Maven, the following dependency adds logging for you:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -19,7 +19,7 @@ If Logback is available, it is the first choice.
If the only change you need to make to logging is to set the levels of various loggers, you can do so in `application.properties` by using the "logging.level" prefix, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
logging:
level:
......@@ -55,7 +55,7 @@ In addition, a legacy `base.xml` file is provided for compatibility with earlier
A typical custom `logback.xml` file would look something like this:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
......@@ -91,7 +91,7 @@ Any `logback-spring.groovy` files will not be detected.
==== Configure Logback for File-only Output
If you want to disable console logging and write output only to a file, you need a custom `logback-spring.xml` that imports `file-appender.xml` but not `console-appender.xml`, as shown in the following example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
......@@ -106,7 +106,7 @@ If you want to disable console logging and write output only to a file, you need
You also need to add `logging.file.name` to your `application.properties` or `application.yaml`, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
logging:
file:
......@@ -124,7 +124,7 @@ If you do not use the starters, you need to provide (at least) `spring-jcl` in a
The recommended path is through the starters, even though it requires some jiggling.
The following example shows how to set up the starters in Maven:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -148,7 +148,7 @@ The following example shows how to set up the starters in Maven:
And the following example shows one way to set up the starters in Gradle:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
......
......@@ -11,7 +11,7 @@ If your JMS broker does not support transacted sessions, you have to disable the
If you create your own `JmsListenerContainerFactory`, there is nothing to do, since, by default it cannot be transacted.
If you want to use the `DefaultJmsListenerContainerFactoryConfigurer` to reuse Spring Boot's default, you can disable transacted sessions, as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.java[]
----
......
......@@ -16,7 +16,7 @@ This is possible in both Maven and Gradle.
You can automatically expand properties from the Maven project by using resource filtering.
If you use the `spring-boot-starter-parent`, you can then refer to your Maven '`project properties`' with `@..@` placeholders, as shown in the following example:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
app:
encoding: "@project.build.sourceEncoding@"
......@@ -33,7 +33,7 @@ See the {spring-boot-maven-plugin-docs}#getting-started[plugin usage page] for m
If you do not use the starter parent, you need to include the following element inside the `<build/>` element of your `pom.xml`:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<resources>
<resource>
......@@ -45,7 +45,7 @@ If you do not use the starter parent, you need to include the following element
You also need to include the following element inside `<plugins/>`:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<plugin>
<groupId>org.apache.maven.plugins</groupId>
......@@ -69,7 +69,7 @@ If that property is not set to `false`, these may be expanded by the build.
==== Automatic Property Expansion Using Gradle
You can automatically expand properties from the Gradle project by configuring the Java plugin's `processResources` task to do so, as shown in the following example:
[source,gradle,indent=0]
[source,gradle,indent=0,subs="verbatim"]
----
processResources {
expand(project.properties)
......@@ -78,7 +78,7 @@ You can automatically expand properties from the Gradle project by configuring t
You can then refer to your Gradle project's properties by using placeholders, as shown in the following example:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
app:
name: "${name}"
......@@ -97,7 +97,7 @@ A `SpringApplication` has bean property setters, so you can use its Java API as
Alternatively, you can externalize the configuration by setting properties in `+spring.main.*+`.
For example, in `application.properties`, you might have the following settings:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
main:
......@@ -110,21 +110,21 @@ Then the Spring Boot banner is not printed on startup, and the application is no
Properties defined in external configuration override and replace the values specified with the Java API, with the notable exception of the primary sources.
Primary sources are those provided to the `SpringApplication` constructor:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/propertiesandconfiguration/externalizeconfiguration/application/MyApplication.java[]
----
Or to `sources(...)` method of a `SpringApplicationBuilder`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/propertiesandconfiguration/externalizeconfiguration/builder/MyApplication.java[]
----
Given the examples above, if we have the following configuration:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
main:
......@@ -165,7 +165,7 @@ See {spring-boot-module-code}/context/config/ConfigFileApplicationListener.java[
Some people like to use (for example) `--port=9000` instead of `--server.port=9000` to set configuration properties on the command line.
You can enable this behavior by using placeholders in `application.properties`, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
port: "${port:8080}"
......@@ -183,7 +183,7 @@ In those two platforms, the `PORT` environment variable is set automatically and
=== Use YAML for External Properties
YAML is a superset of JSON and, as such, is a convenient syntax for storing external properties in a hierarchical format, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes"]
[source,yaml,indent=0,subs="verbatim"]
----
spring:
application:
......@@ -201,7 +201,7 @@ A YAML file is parsed to a Java `Map<String,Object>` (like a JSON object), and S
The preceding example YAML corresponds to the following `application.properties` file:
[source,properties,indent=0,subs="verbatim,quotes,attributes",configprops]
[source,properties,indent=0,subs="verbatim",configprops]
----
spring.application.name=cruncher
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
......@@ -218,14 +218,14 @@ See "`<<features#features.external-config.yaml>>`" in the '`Spring Boot features
The Spring `Environment` has an API for this, but you would normally set a System property (configprop:spring.profiles.active[]) or an OS environment variable (configprop:spring.profiles.active[format=envvar]).
Also, you can launch your application with a `-D` argument (remember to put it before the main class or jar archive), as follows:
[indent=0,subs="verbatim,quotes,attributes"]
[indent=0,subs="verbatim"]
----
$ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar
----
In Spring Boot, you can also set the active profile in `application.properties`, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
profiles:
......@@ -246,7 +246,7 @@ Spring Boot supports multi-document YAML and Properties files (see <<features#fe
If a document contains a `spring.config.activate.on-profile` key, then the profiles value (a comma-separated list of profiles or a profile expression) is fed into the Spring `Environment.acceptsProfiles()` method.
If the profile expression matches then that document is included in the final merge (otherwise, it is not), as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim,attributes",configprops,configblocks]
----
server:
port: 9000
......
......@@ -28,7 +28,7 @@ If you use Tomcat as a servlet container, then Spring Boot adds Tomcat's own `Re
The standard behavior is determined by the presence or absence of certain request headers (`x-forwarded-for` and `x-forwarded-proto`), whose names are conventional, so it should work with most front-end proxies.
You can switch on the valve by adding some entries to `application.properties`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
tomcat:
......@@ -42,7 +42,7 @@ Alternatively, you can add the `RemoteIpValve` by customizing the `TomcatServlet
To configure Spring Security to require a secure channel for all (or some) requests, consider adding your own `SecurityFilterChain` bean that adds the following `HttpSecurity` configuration:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/security/enablehttps/MySecurityConfig.java[]
----
......@@ -10,7 +10,7 @@ This section answers common questions about Spring MVC and Spring Boot.
=== Write a JSON REST Service
Any Spring `@RestController` in a Spring Boot application should render JSON response by default as long as Jackson2 is on the classpath, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/springmvc/writejsonrestservice/MyController.java[]
----
......@@ -26,7 +26,7 @@ If you have the Jackson XML extension (`jackson-dataformat-xml`) on the classpat
The previous example that we used for JSON would work.
To use the Jackson XML renderer, add the following dependency to your project:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
......@@ -36,7 +36,7 @@ To use the Jackson XML renderer, add the following dependency to your project:
If Jackson's XML extension is not available and JAXB is available, XML can be rendered with the additional requirement of having `MyThing` annotated as `@XmlRootElement`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/springmvc/writexmlrestservice/MyThing.java[]
----
......@@ -44,7 +44,7 @@ include::{docs-java}/howto/springmvc/writexmlrestservice/MyThing.java[]
JAXB is only available out of the box with Java 8.
If you're using a more recent Java generation, add the following dependency to your project:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependency>
<groupId>org.glassfish.jaxb</groupId>
......
......@@ -5,7 +5,7 @@ It integrates with JUnit, allowing you to write a test class that can start up a
Testcontainers is especially useful for writing integration tests that talk to a real backend service such as MySQL, MongoDB, Cassandra etc.
Testcontainers can be used in a Spring Boot test as follows:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/testcontainers/vanilla/MyIntegrationTests.java
----
......@@ -15,7 +15,7 @@ In most cases, you will need to configure the application using details from the
This can be done with a static `@DynamicPropertySource` method that allows adding dynamic property values to the Spring Environment.
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/testcontainers/dynamicproperties/MyIntegrationTests.java
----
......
......@@ -3,7 +3,7 @@
Spring Security provides support for running tests as a specific user.
For example, the test in the snippet below will run with an authenticated user that has the `ADMIN` role.
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/testingwithspringsecurity/MySecurityTests.java[]
----
......
......@@ -14,7 +14,7 @@ The first step in producing a deployable war file is to provide a `SpringBootSer
Doing so makes use of Spring Framework's Servlet 3.0 support and lets you configure your application when it is launched by the servlet container.
Typically, you should update your application's main class to extend `SpringBootServletInitializer`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/traditionaldeployment/war/MyApplication.java[]
----
......@@ -22,14 +22,14 @@ include::{docs-java}/howto/traditionaldeployment/war/MyApplication.java[]
The next step is to update your build configuration such that your project produces a war file rather than a jar file.
If you use Maven and `spring-boot-starter-parent` (which configures Maven's war plugin for you), all you need to do is to modify `pom.xml` to change the packaging to war, as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<packaging>war</packaging>
----
If you use Gradle, you need to modify `build.gradle` to apply the war plugin to the project, as follows:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
apply plugin: 'war'
----
......@@ -39,7 +39,7 @@ To do so, you need to mark the embedded servlet container dependency as being pr
If you use Maven, the following example marks the servlet container (Tomcat, in this case) as being provided:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependencies>
<!-- … -->
......@@ -54,7 +54,7 @@ If you use Maven, the following example marks the servlet container (Tomcat, in
If you use Gradle, the following example marks the servlet container (Tomcat, in this case) as being provided:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
dependencies {
// …
......@@ -79,7 +79,7 @@ See the https://spring.io/guides/gs/convert-jar-to-war/[Getting Started Guide on
To create a deployable war by extending `SpringBootServletInitializer` (for example, in a class called `Application`) and adding the Spring Boot `@SpringBootApplication` annotation, use code similar to that shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/MyApplication.java[tag=!main]
----
......@@ -101,7 +101,7 @@ If you have other features in your application (for instance, using other servle
Once the war file is working, you can make it executable by adding a `main` method to your `Application`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/MyApplication.java[tag=main]
----
......@@ -110,7 +110,7 @@ include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/MyAp
====
If you intend to start your application as a war or as an executable application, you need to share the customizations of the builder in a method that is both available to the `SpringBootServletInitializer` callback and in the `main` method in a class similar to the following:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/both/MyApplication.java[]
----
......@@ -144,7 +144,7 @@ To deploy a Spring Boot application to WebLogic, you must ensure that your servl
A typical initializer for WebLogic should resemble the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/traditionaldeployment/weblogic/MyApplication.java[]
----
......@@ -152,7 +152,7 @@ include::{docs-java}/howto/traditionaldeployment/weblogic/MyApplication.java[]
If you use Logback, you also need to tell WebLogic to prefer the packaged version rather than the version that was pre-installed with the server.
You can do so by adding a `WEB-INF/weblogic.xml` file with the following contents:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
......
......@@ -18,7 +18,7 @@ To help with this process, Spring Boot provides a separate starter for each of t
The following Maven example shows how to exclude Tomcat and include Jetty for Spring MVC:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<properties>
<servlet-api.version>3.1.0</servlet-api.version>
......@@ -46,7 +46,7 @@ If you wish to use Jetty 10, which does support Servlet 4.0, override the `jetty
The following Gradle example shows how to use Undertow in place of Reactor Netty for Spring WebFlux:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
configurations.all {
resolutionStrategy.dependencySubstitution.all { dependency ->
......@@ -71,7 +71,7 @@ NOTE: `spring-boot-starter-reactor-netty` is required to use the `WebClient` cla
If your classpath contains the necessary bits to start a web server, Spring Boot will automatically start it.
To disable this behavior configure the `WebApplicationType` in your `application.properties`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
main:
......@@ -104,7 +104,7 @@ The best way to get that and be sure it has been initialized is to add a `@Bean`
Tests that use `@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)` can also inject the actual port into a field by using the `@LocalServerPort` annotation, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/webserver/discoverport/MyWebIntegrationTests.java[]
----
......@@ -124,7 +124,7 @@ Contrary to a test, application code callbacks are processed early (before the v
HTTP response compression is supported by Jetty, Tomcat, and Undertow.
It can be enabled in `application.properties`, as follows:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
compression:
......@@ -154,7 +154,7 @@ You can configure this behavior by setting the configprop:server.compression.mim
SSL can be configured declaratively by setting the various `+server.ssl.*+` properties, typically in `application.properties` or `application.yml`.
The following example shows setting SSL properties in `application.properties`:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
port: 8443
......@@ -194,7 +194,7 @@ More on this in the https://tomcat.apache.org/tomcat-9.0-doc/apr.html[official T
Starting Tomcat 9.0.x on JDK 8 with HTTP/2 and SSL enabled but without that native support logs the following error:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim"]
----
ERROR 8787 --- [ main] o.a.coyote.http11.Http11NioProtocol : The upgrade handler [org.apache.coyote.http2.Http2Protocol] for [h2] only supports upgrade via ALPN but has been configured for the ["https-jsse-nio-8443"] connector that does not support ALPN.
----
......@@ -246,7 +246,7 @@ You can declare such a component and get access to the server factory relevant t
The example below is for Tomcat with the `spring-boot-starter-web` (Servlet stack):
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/webserver/configure/MyTomcatWebServerCustomizer.java[]
----
......@@ -319,7 +319,7 @@ Like any other Spring bean, you can define the order of Servlet filter beans; pl
As <<howto#howto.webserver.add-servlet-filter-listener.spring-bean,described earlier>>, any `Servlet` or `Filter` beans are registered with the servlet container automatically.
To disable registration of a particular `Filter` or `Servlet` bean, create a registration bean for it and mark it as disabled, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/webserver/addservletfilterlistener/springbean/disable/MyFilterConfiguration.java[]
----
......@@ -339,7 +339,7 @@ Access logs can be configured for Tomcat, Undertow, and Jetty through their resp
For instance, the following settings log access on Tomcat with a {tomcat-docs}/config/valve.html#Access_Logging[custom pattern].
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
tomcat:
......@@ -355,7 +355,7 @@ In the preceding example, the logs are available in `my-tomcat/logs` relative to
Access logging for Undertow can be configured in a similar fashion, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
undertow:
......@@ -369,7 +369,7 @@ You can customize this location by setting the configprop:server.undertow.access
Finally, access logging for Jetty can also be configured as follows:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
jetty:
......@@ -410,7 +410,7 @@ In all other instances, it defaults to `NONE`.
==== Customize Tomcat's Proxy Configuration
If you use Tomcat, you can additionally configure the names of the headers used to carry "`forwarded`" information, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
tomcat:
......@@ -423,7 +423,7 @@ Tomcat is also configured with a default regular expression that matches interna
By default, IP addresses in `10/8`, `192.168/16`, `169.254/16` and `127/8` are trusted.
You can customize the valve's configuration by adding an entry to `application.properties`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
tomcat:
......@@ -441,7 +441,7 @@ You can take complete control of the configuration of Tomcat's `RemoteIpValve` b
=== Enable Multiple Connectors with Tomcat
You can add an `org.apache.catalina.connector.Connector` to the `TomcatServletWebServerFactory`, which can allow multiple connectors, including HTTP and HTTPS connectors, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.java[]
----
......@@ -461,7 +461,7 @@ If at all possible, you should consider updating your code to only store values
If, however, you cannot change the way that cookies are written, you can instead configure Tomcat to use a `LegacyCookieProcessor`.
To switch to the `LegacyCookieProcessor`, use an `WebServerFactoryCustomizer` bean that adds a `TomcatContextCustomizer`, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/webserver/usetomcatlegacycookieprocessor/MyLegacyCookieProcessorConfiguration.java[]
----
......@@ -474,7 +474,7 @@ Embedded Tomcat's MBean registry is disabled by default.
This minimizes Tomcat's memory footprint.
If you want to use Tomcat's MBeans, for example so that they can be used to expose metrics via Micrometer, you must use the configprop:server.tomcat.mbeanregistry.enabled[] property to do so, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
server:
tomcat:
......@@ -488,7 +488,7 @@ server:
=== Enable Multiple Listeners with Undertow
Add an `UndertowBuilderCustomizer` to the `UndertowServletWebServerFactory` and add a listener to the `Builder`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/webserver/enablemultiplelistenersinundertow/MyUndertowConfiguration.java[]
----
......@@ -499,7 +499,7 @@ include::{docs-java}/howto/webserver/enablemultiplelistenersinundertow/MyUnderto
=== Create WebSocket Endpoints Using @ServerEndpoint
If you want to use `@ServerEndpoint` in a Spring Boot application that used an embedded container, you must declare a single `ServerEndpointExporter` `@Bean`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/webserver/createwebsocketendpointsusingserverendpoint/MyWebSocketConfiguration.java[]
----
......
......@@ -25,7 +25,7 @@ Doing so enables debug logs for a selection of core loggers and logs a condition
=== Disabling Specific Auto-configuration Classes
If you find that specific auto-configuration classes that you do not want are being applied, you can use the exclude attribute of `@SpringBootApplication` to disable them, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/using/autoconfiguration/disablingspecific/MyApplication.java[]
----
......
......@@ -47,7 +47,7 @@ The `spring-boot-antlib` "`AntLib`" module is also available to help Ant create
To declare dependencies, a typical `ivy.xml` file looks something like the following example:
[source,xml,indent=0]
[source,xml,indent=0,subs="verbatim"]
----
<ivy-module version="2.0">
<info organisation="org.springframework.boot" module="spring-boot-sample-ant" />
......@@ -64,7 +64,7 @@ To declare dependencies, a typical `ivy.xml` file looks something like the follo
A typical `build.xml` looks like the following example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim,attributes"]
----
<project
xmlns:ivy="antlib:org.apache.ivy.ant"
......
......@@ -5,7 +5,7 @@ The `spring-boot-devtools` module can be included in any project to provide addi
To include devtools support, add the module dependency to your build, as shown in the following listings for Maven and Gradle:
.Maven
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<dependencies>
<dependency>
......@@ -17,7 +17,7 @@ To include devtools support, add the module dependency to your build, as shown i
----
.Gradle
[source,gradle,indent=0,subs="attributes"]
[source,gradle,indent=0,subs="verbatim"]
----
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
......@@ -117,7 +117,7 @@ The report shows the changes to your application's auto-configuration as you mak
To disable the logging of the report, set the following property:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
spring:
devtools:
......@@ -135,7 +135,7 @@ By default, changing resources in `/META-INF/maven`, `/META-INF/resources`, `/re
If you want to customize these exclusions, you can use the configprop:spring.devtools.restart.exclude[] property.
For example, to exclude only `/static` and `/public` you would set the following property:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
spring:
devtools:
......@@ -162,7 +162,7 @@ In most cases, you can set this property in your `application.properties` (doing
If you need to _completely_ disable restart support (for example, because it does not work with a specific library), you need to set the configprop:spring.devtools.restart.enabled[] `System` property to `false` before calling `SpringApplication.run(...)`, as shown in the following example:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/devtools/restart/disable/MyApplication.java[]
----
......@@ -191,7 +191,7 @@ For example, if you have a project with the following structure:
Then your `trigger-file` property would be:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
devtools:
......@@ -224,7 +224,7 @@ The `spring-devtools.properties` file can contain properties prefixed with `rest
The `include` elements are items that should be pulled up into the "`restart`" classloader, and the `exclude` elements are items that should be pushed down into the "`base`" classloader.
The value of the property is a regex pattern that is applied to the classpath, as shown in the following example:
[source,yaml,indent=0,configblocks]
[source,yaml,indent=0,subs="verbatim",configblocks]
----
restart:
exclude:
......@@ -277,7 +277,7 @@ You can configure global devtools settings by adding any of the following files
Any properties added to these file apply to _all_ Spring Boot applications on your machine that use devtools.
For example, to configure restart to always use a <<using#using.devtools.restart.triggerfile, trigger file>>, you would add the following property to your `spring-boot-devtools` file:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
devtools:
......@@ -304,7 +304,7 @@ Profile specific filenames (of the form `spring-boot-devtools-<profile>.properti
Since Spring Boot relies entirely on the IDE to compile and copy files into the location from where Spring Boot can read them, you might find that there are times when certain changes are not reflected when devtools restarts the application.
If you observe such problems constantly, try increasing the `spring.devtools.restart.poll-interval` and `spring.devtools.restart.quiet-period` parameters to the values that fit your development environment:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
devtools:
......@@ -328,7 +328,7 @@ You should never enable support on a production deployment.
To enable it, you need to make sure that `devtools` is included in the repackaged archive, as shown in the following listing:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
[source,xml,indent=0,subs="verbatim"]
----
<build>
<plugins>
......@@ -368,7 +368,7 @@ For example, if you are using Eclipse or STS and you have a project named `my-ap
A running remote client might resemble the following listing:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim"]
----
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ ___ _ \ \ \ \
......
......@@ -30,7 +30,7 @@ STS users can use the `Relaunch` button rather than the `Run` button to ensure t
=== Running as a Packaged Application
If you use the Spring Boot Maven or Gradle plugins to create an executable jar, you can run your application using `java -jar`, as shown in the following example:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim"]
----
$ java -jar target/myapplication-0.0.1-SNAPSHOT.jar
----
......@@ -38,7 +38,7 @@ If you use the Spring Boot Maven or Gradle plugins to create an executable jar,
It is also possible to run a packaged application with remote debugging support enabled.
Doing so lets you attach a debugger to your packaged application, as shown in the following example:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim"]
----
$ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \
-jar target/myapplication-0.0.1-SNAPSHOT.jar
......@@ -52,14 +52,14 @@ The Spring Boot Maven plugin includes a `run` goal that can be used to quickly c
Applications run in an exploded form, as they do in your IDE.
The following example shows a typical Maven command to run a Spring Boot application:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim"]
----
$ mvn spring-boot:run
----
You might also want to use the `MAVEN_OPTS` operating system environment variable, as shown in the following example:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim"]
----
$ export MAVEN_OPTS=-Xmx1024m
----
......@@ -71,14 +71,14 @@ You might also want to use the `MAVEN_OPTS` operating system environment variabl
The Spring Boot Gradle plugin also includes a `bootRun` task that can be used to run your application in an exploded form.
The `bootRun` task is added whenever you apply the `org.springframework.boot` and `java` plugins and is shown in the following example:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim"]
----
$ gradle bootRun
----
You might also want to use the `JAVA_OPTS` operating system environment variable, as shown in the following example:
[indent=0,subs="attributes"]
[indent=0,subs="verbatim"]
----
$ export JAVA_OPTS=-Xmx1024m
----
......
......@@ -8,14 +8,14 @@ All of your application components (`@Component`, `@Service`, `@Repository`, `@C
The following example shows a `@Service` Bean that uses constructor injection to obtain a required `RiskAssessor` bean:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/using/springbeansanddependencyinjection/singleconstructor/MyAccountService.java[]
----
If a bean has more than one constructor, you'll need to mark the one you want Spring to use with `@Autowired`:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/using/springbeansanddependencyinjection/multipleconstructors/MyAccountService.java[]
----
......
......@@ -48,7 +48,7 @@ The following listing shows a typical layout:
The `MyApplication.java` file would declare the `main` method, along with the basic `@SpringBootApplication`, as follows:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/using/structuringyourcode/locatingthemainclass/MyApplication.java[]
----
......@@ -7,7 +7,7 @@ A single `@SpringBootApplication` annotation can be used to enable those three f
* `@ComponentScan`: enable `@Component` scan on the package where the application is located (see <<using#using.structuring-your-code,the best practices>>)
* `@Configuration`: allow to register extra beans in the context or import additional configuration classes
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/using/usingthespringbootapplicationannotation/springapplication/MyApplication.java[]
----
......@@ -19,7 +19,7 @@ NOTE: `@SpringBootApplication` also provides aliases to customize the attributes
None of these features are mandatory and you may choose to replace this single annotation by any of the features that it enables.
For instance, you may not want to use component scan or configuration properties scan in your application:
[source,java,indent=0]
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/using/usingthespringbootapplicationannotation/individualannotations/MyApplication.java[]
----
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment