Use consistent asciidoctor subs attribute

Closes gh-25101
This commit is contained in:
Phillip Webb
2021-05-04 10:42:11 -07:00
parent 979fa12ca9
commit 711a0c19e6
72 changed files with 588 additions and 588 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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