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

Use consistent asciidoctor subs attribute

Closes gh-25101
parent 979fa12c
...@@ -17,7 +17,7 @@ If you want to fully disable the `/cloudfoundryapplication` endpoints, you can a ...@@ -17,7 +17,7 @@ If you want to fully disable the `/cloudfoundryapplication` endpoints, you can a
.application.properties .application.properties
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
management: management:
cloudfoundry: cloudfoundry:
...@@ -32,7 +32,7 @@ By default, the security verification for `/cloudfoundryapplication` endpoints m ...@@ -32,7 +32,7 @@ By default, the security verification for `/cloudfoundryapplication` endpoints m
If your Cloud Foundry UAA or Cloud Controller services use self-signed certificates, you need to set the following property: If your Cloud Foundry UAA or Cloud Controller services use self-signed certificates, you need to set the following property:
.application.properties .application.properties
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
management: management:
cloudfoundry: cloudfoundry:
...@@ -50,7 +50,7 @@ If you expect the Cloud Foundry endpoints to always be available at `/cloudfound ...@@ -50,7 +50,7 @@ If you expect the Cloud Foundry endpoints to always be available at `/cloudfound
The configuration will differ depending on the web server in use. The configuration will differ depending on the web server in use.
For Tomcat, the following configuration can be added: For Tomcat, the following configuration can be added:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/actuator/cloudfoundry/customcontextpath/MyCloudFoundryConfiguration.java[] include::{docs-java}/actuator/cloudfoundry/customcontextpath/MyCloudFoundryConfiguration.java[]
---- ----
...@@ -11,7 +11,7 @@ Actuators can generate a large amount of motion from a small change. ...@@ -11,7 +11,7 @@ Actuators can generate a large amount of motion from a small change.
To add the actuator to a Maven based project, add the following '`Starter`' dependency: To add the actuator to a Maven based project, add the following '`Starter`' dependency:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependencies> <dependencies>
<dependency> <dependency>
...@@ -23,7 +23,7 @@ To add the actuator to a Maven based project, add the following '`Starter`' depe ...@@ -23,7 +23,7 @@ To add the actuator to a Maven based project, add the following '`Starter`' depe
For Gradle, use the following declaration: For Gradle, use the following declaration:
[source,gradle,indent=0] [source,gradle,indent=0,subs="verbatim"]
---- ----
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-actuator'
......
...@@ -18,7 +18,7 @@ To solve this problem, you can set the configprop:spring.jmx.unique-names[] prop ...@@ -18,7 +18,7 @@ To solve this problem, you can set the configprop:spring.jmx.unique-names[] prop
You can also customize the JMX domain under which endpoints are exposed. You can also customize the JMX domain under which endpoints are exposed.
The following settings show an example of doing so in `application.properties`: The following settings show an example of doing so in `application.properties`:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
jmx: jmx:
...@@ -35,7 +35,7 @@ The following settings show an example of doing so in `application.properties`: ...@@ -35,7 +35,7 @@ The following settings show an example of doing so in `application.properties`:
=== Disabling JMX Endpoints === Disabling JMX Endpoints
If you do not want to expose endpoints over JMX, you can set the configprop:management.endpoints.jmx.exposure.exclude[] property to `*`, as shown in the following example: If you do not want to expose endpoints over JMX, you can set the configprop:management.endpoints.jmx.exposure.exclude[] property to `*`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
management: management:
endpoints: endpoints:
...@@ -52,7 +52,7 @@ Jolokia is a JMX-HTTP bridge that provides an alternative method of accessing JM ...@@ -52,7 +52,7 @@ Jolokia is a JMX-HTTP bridge that provides an alternative method of accessing JM
To use Jolokia, include a dependency to `org.jolokia:jolokia-core`. To use Jolokia, include a dependency to `org.jolokia:jolokia-core`.
For example, with Maven, you would add the following dependency: For example, with Maven, you would add the following dependency:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependency> <dependency>
<groupId>org.jolokia</groupId> <groupId>org.jolokia</groupId>
...@@ -75,7 +75,7 @@ Jolokia has a number of settings that you would traditionally configure by setti ...@@ -75,7 +75,7 @@ Jolokia has a number of settings that you would traditionally configure by setti
With Spring Boot, you can use your `application.properties` file. With Spring Boot, you can use your `application.properties` file.
To do so, prefix the parameter with `management.endpoint.jolokia.config.`, as shown in the following example: To do so, prefix the parameter with `management.endpoint.jolokia.config.`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
management: management:
endpoint: endpoint:
...@@ -90,7 +90,7 @@ To do so, prefix the parameter with `management.endpoint.jolokia.config.`, as sh ...@@ -90,7 +90,7 @@ To do so, prefix the parameter with `management.endpoint.jolokia.config.`, as sh
==== Disabling Jolokia ==== Disabling Jolokia
If you use Jolokia but do not want Spring Boot to configure it, set the configprop:management.endpoint.jolokia.enabled[] property to `false`, as follows: If you use Jolokia but do not want Spring Boot to configure it, set the configprop:management.endpoint.jolokia.enabled[] property to `false`, as follows:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
management: management:
endpoint: endpoint:
......
...@@ -21,7 +21,7 @@ These levels can be one of: ...@@ -21,7 +21,7 @@ These levels can be one of:
=== Configure a Logger === Configure a Logger
To configure a given logger, `POST` a partial entity to the resource's URI, as shown in the following example: To configure a given logger, `POST` a partial entity to the resource's URI, as shown in the following example:
[source,json,indent=0] [source,json,indent=0,subs="verbatim"]
---- ----
{ {
"configuredLevel": "DEBUG" "configuredLevel": "DEBUG"
......
...@@ -17,7 +17,7 @@ Sometimes, it is useful to customize the prefix for the management endpoints. ...@@ -17,7 +17,7 @@ Sometimes, it is useful to customize the prefix for the management endpoints.
For example, your application might already use `/actuator` for another purpose. For example, your application might already use `/actuator` for another purpose.
You can use the configprop:management.endpoints.web.base-path[] property to change the prefix for your management endpoint, as shown in the following example: You can use the configprop:management.endpoints.web.base-path[] property to change the prefix for your management endpoint, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
management: management:
endpoints: endpoints:
...@@ -34,7 +34,7 @@ If you want to map endpoints to a different path, you can use the configprop:man ...@@ -34,7 +34,7 @@ If you want to map endpoints to a different path, you can use the configprop:man
The following example remaps `/actuator/health` to `/healthcheck`: The following example remaps `/actuator/health` to `/healthcheck`:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
management: management:
endpoints: endpoints:
...@@ -53,7 +53,7 @@ If, however, your application runs inside your own data center, you may prefer t ...@@ -53,7 +53,7 @@ If, however, your application runs inside your own data center, you may prefer t
You can set the configprop:management.server.port[] property to change the HTTP port, as shown in the following example: You can set the configprop:management.server.port[] property to change the HTTP port, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
management: management:
server: server:
...@@ -70,7 +70,7 @@ If you want to use a custom management port on Cloud Foundry, you will need to e ...@@ -70,7 +70,7 @@ If you want to use a custom management port on Cloud Foundry, you will need to e
When configured to use a custom port, the management server can also be configured with its own SSL by using the various `management.server.ssl.*` properties. When configured to use a custom port, the management server can also be configured with its own SSL by using the various `management.server.ssl.*` properties.
For example, doing so lets a management server be available over HTTP while the main application uses HTTPS, as shown in the following property settings: For example, doing so lets a management server be available over HTTP while the main application uses HTTPS, as shown in the following property settings:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
port: 8443 port: 8443
...@@ -87,7 +87,7 @@ For example, doing so lets a management server be available over HTTP while the ...@@ -87,7 +87,7 @@ For example, doing so lets a management server be available over HTTP while the
Alternatively, both the main server and the management server can use SSL but with different key stores, as follows: Alternatively, both the main server and the management server can use SSL but with different key stores, as follows:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
port: 8443 port: 8443
...@@ -115,7 +115,7 @@ NOTE: You can listen on a different address only when the port differs from the ...@@ -115,7 +115,7 @@ NOTE: You can listen on a different address only when the port differs from the
The following example `application.properties` does not allow remote management connections: The following example `application.properties` does not allow remote management connections:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
management: management:
server: server:
...@@ -129,7 +129,7 @@ The following example `application.properties` does not allow remote management ...@@ -129,7 +129,7 @@ The following example `application.properties` does not allow remote management
=== Disabling HTTP Endpoints === Disabling HTTP Endpoints
If you do not want to expose endpoints over HTTP, you can set the management port to `-1`, as shown in the following example: If you do not want to expose endpoints over HTTP, you can set the management port to `-1`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
management: management:
server: server:
...@@ -138,7 +138,7 @@ If you do not want to expose endpoints over HTTP, you can set the management por ...@@ -138,7 +138,7 @@ If you do not want to expose endpoints over HTTP, you can set the management por
This can be achieved using the configprop:management.endpoints.web.exposure.exclude[] property as well, as shown in the following example: This can be achieved using the configprop:management.endpoints.web.exposure.exclude[] property as well, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
management: management:
endpoints: endpoints:
......
...@@ -4,7 +4,7 @@ The Spring Boot AntLib module provides basic Spring Boot support for Apache Ant. ...@@ -4,7 +4,7 @@ The Spring Boot AntLib module provides basic Spring Boot support for Apache Ant.
You can use the module to create executable jars. You can use the module to create executable jars.
To use the module, you need to declare an additional `spring-boot` namespace in your `build.xml`, as shown in the following example: To use the module, you need to declare an additional `spring-boot` namespace in your `build.xml`, as shown in the following example:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<project xmlns:ivy="antlib:org.apache.ivy.ant" <project xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:spring-boot="antlib:org.springframework.boot.ant" xmlns:spring-boot="antlib:org.springframework.boot.ant"
...@@ -15,7 +15,7 @@ To use the module, you need to declare an additional `spring-boot` namespace in ...@@ -15,7 +15,7 @@ To use the module, you need to declare an additional `spring-boot` namespace in
You need to remember to start Ant using the `-lib` option, as shown in the following example: You need to remember to start Ant using the `-lib` option, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim,attributes"]
---- ----
$ ant -lib <directory containing spring-boot-antlib-{spring-boot-version}.jar> $ ant -lib <directory containing spring-boot-antlib-{spring-boot-version}.jar>
---- ----
...@@ -75,7 +75,7 @@ The following nested elements can be used with the task: ...@@ -75,7 +75,7 @@ The following nested elements can be used with the task:
This section shows two examples of Ant tasks. This section shows two examples of Ant tasks.
.Specify +start-class+ .Specify +start-class+
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<spring-boot:exejar destfile="target/my-application.jar" <spring-boot:exejar destfile="target/my-application.jar"
classes="target/classes" start-class="com.example.MyApplication"> classes="target/classes" start-class="com.example.MyApplication">
...@@ -89,7 +89,7 @@ This section shows two examples of Ant tasks. ...@@ -89,7 +89,7 @@ This section shows two examples of Ant tasks.
---- ----
.Detect +start-class+ .Detect +start-class+
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<exejar destfile="target/my-application.jar" classes="target/classes"> <exejar destfile="target/my-application.jar" classes="target/classes">
<lib> <lib>
...@@ -130,19 +130,19 @@ The following attributes are supported: ...@@ -130,19 +130,19 @@ The following attributes are supported:
This section contains three examples of using `findmainclass`. This section contains three examples of using `findmainclass`.
.Find and log .Find and log
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<findmainclass classesroot="target/classes" /> <findmainclass classesroot="target/classes" />
---- ----
.Find and set .Find and set
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<findmainclass classesroot="target/classes" property="main-class" /> <findmainclass classesroot="target/classes" property="main-class" />
---- ----
.Override and set .Override and set
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<findmainclass mainclass="com.example.MainClass" property="main-class" /> <findmainclass mainclass="com.example.MainClass" property="main-class" />
---- ----
...@@ -37,7 +37,7 @@ An exception is thrown if more than one candidate is found. ...@@ -37,7 +37,7 @@ An exception is thrown if more than one candidate is found.
=== Example Repackage Implementation === Example Repackage Implementation
The following example shows a typical repackage implementation: The following example shows a typical repackage implementation:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/buildtoolplugins/otherbuildsystems/examplerepackageimplementation/MyBuildTool.java[] include::{docs-java}/buildtoolplugins/otherbuildsystems/examplerepackageimplementation/MyBuildTool.java[]
---- ----
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Spring Framework 4.0 has native support for a `beans{}` "`DSL`" (borrowed from https://grails.org/[Grails]), and you can embed bean definitions in your Groovy application scripts by using the same format. Spring Framework 4.0 has native support for a `beans{}` "`DSL`" (borrowed from https://grails.org/[Grails]), and you can embed bean definitions in your Groovy application scripts by using the same format.
This is sometimes a good way to include external features like middleware declarations, as shown in the following example: This is sometimes a good way to include external features like middleware declarations, as shown in the following example:
[source,groovy,indent=0] [source,groovy,indent=0,subs="verbatim"]
---- ----
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class Application implements CommandLineRunner { class Application implements CommandLineRunner {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Once you have installed the CLI, you can run it by typing `spring` and pressing Enter at the command line. Once you have installed the CLI, you can run it by typing `spring` and pressing Enter at the command line.
If you run `spring` without any arguments, a help screen is displayed, as follows: If you run `spring` without any arguments, a help screen is displayed, as follows:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ spring $ spring
usage: spring [--help] [--version] usage: spring [--help] [--version]
...@@ -41,7 +41,7 @@ You can type `spring help` to get more details about any of the supported comman ...@@ -41,7 +41,7 @@ You can type `spring help` to get more details about any of the supported comman
The `version` command provides a quick way to check which version of Spring Boot you are using, as follows: The `version` command provides a quick way to check which version of Spring Boot you are using, as follows:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim,attributes"]
---- ----
$ spring version $ spring version
Spring CLI v{spring-boot-version} Spring CLI v{spring-boot-version}
...@@ -57,28 +57,28 @@ The Spring Boot CLI is completely self-contained, so you do not need any externa ...@@ -57,28 +57,28 @@ The Spring Boot CLI is completely self-contained, so you do not need any externa
The following example shows a "`hello world`" web application written in Groovy: The following example shows a "`hello world`" web application written in Groovy:
.hello.groovy .hello.groovy
[source,groovy,indent=0,subs="verbatim,quotes,attributes"] [source,groovy,indent=0,subs="verbatim"]
---- ----
include::{docs-groovy}/cli/usingthecli/run/WebApplication.groovy[tag=*] include::{docs-groovy}/cli/usingthecli/run/WebApplication.groovy[tag=*]
---- ----
To compile and run the application, type the following command: To compile and run the application, type the following command:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ spring run hello.groovy $ spring run hello.groovy
---- ----
To pass command-line arguments to the application, use `--` to separate the commands from the "`spring`" command arguments, as shown in the following example: To pass command-line arguments to the application, use `--` to separate the commands from the "`spring`" command arguments, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ spring run hello.groovy -- --server.port=9000 $ spring run hello.groovy -- --server.port=9000
---- ----
To set JVM command line arguments, you can use the `JAVA_OPTS` environment variable, as shown in the following example: To set JVM command line arguments, you can use the `JAVA_OPTS` environment variable, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ JAVA_OPTS=-Xmx1024m spring run hello.groovy $ JAVA_OPTS=-Xmx1024m spring run hello.groovy
---- ----
...@@ -175,7 +175,7 @@ The annotation's value should specify the coordinates (`groupId:artifactId:versi ...@@ -175,7 +175,7 @@ The annotation's value should specify the coordinates (`groupId:artifactId:versi
For example, consider the following declaration: For example, consider the following declaration:
[source,groovy,indent=0] [source,groovy,indent=0,subs="verbatim"]
---- ----
include::{docs-groovy}/cli/usingthecli/run/customdependencymanagement/single/CustomDependencyManagement.groovy[tag=*] include::{docs-groovy}/cli/usingthecli/run/customdependencymanagement/single/CustomDependencyManagement.groovy[tag=*]
---- ----
...@@ -184,7 +184,7 @@ The preceding declaration picks up `custom-bom-1.0.0.pom` in a Maven repository ...@@ -184,7 +184,7 @@ The preceding declaration picks up `custom-bom-1.0.0.pom` in a Maven repository
When you specify multiple BOMs, they are applied in the order in which you declare them, as shown in the following example: When you specify multiple BOMs, they are applied in the order in which you declare them, as shown in the following example:
[source,groovy,indent=0] [source,groovy,indent=0,subs="verbatim"]
---- ----
include::{docs-groovy}/cli/usingthecli/run/customdependencymanagement/multiple/CustomDependencyManagement.groovy[tag=*] include::{docs-groovy}/cli/usingthecli/run/customdependencymanagement/multiple/CustomDependencyManagement.groovy[tag=*]
---- ----
...@@ -305,7 +305,7 @@ If you do not use either of these shells (perhaps you are a Windows user), you c ...@@ -305,7 +305,7 @@ If you do not use either of these shells (perhaps you are a Windows user), you c
From inside the embedded shell, you can run other commands directly: From inside the embedded shell, you can run other commands directly:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim,attributes"]
---- ----
$ version $ version
Spring CLI v{spring-boot-version} Spring CLI v{spring-boot-version}
...@@ -322,7 +322,7 @@ To exit the embedded shell, press `ctrl-c`. ...@@ -322,7 +322,7 @@ To exit the embedded shell, press `ctrl-c`.
You can add extensions to the CLI by using the `install` command. You can add extensions to the CLI by using the `install` command.
The command takes one or more sets of artifact coordinates in the format `group:artifact:version`, as shown in the following example: The command takes one or more sets of artifact coordinates in the format `group:artifact:version`, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ spring install com.example:spring-boot-cli-extension:1.0.0.RELEASE $ spring install com.example:spring-boot-cli-extension:1.0.0.RELEASE
---- ----
...@@ -332,7 +332,7 @@ In addition to installing the artifacts identified by the coordinates you supply ...@@ -332,7 +332,7 @@ In addition to installing the artifacts identified by the coordinates you supply
To uninstall a dependency, use the `uninstall` command. To uninstall a dependency, use the `uninstall` command.
As with the `install` command, it takes one or more sets of artifact coordinates in the format of `group:artifact:version`, as shown in the following example: As with the `install` command, it takes one or more sets of artifact coordinates in the format of `group:artifact:version`, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ spring uninstall com.example:spring-boot-cli-extension:1.0.0.RELEASE $ spring uninstall com.example:spring-boot-cli-extension:1.0.0.RELEASE
---- ----
...@@ -341,7 +341,7 @@ It uninstalls the artifacts identified by the coordinates you supply and their d ...@@ -341,7 +341,7 @@ It uninstalls the artifacts identified by the coordinates you supply and their d
To uninstall all additional dependencies, you can use the `--all` option, as shown in the following example: To uninstall all additional dependencies, you can use the `--all` option, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ spring uninstall --all $ spring uninstall --all
---- ----
...@@ -11,7 +11,7 @@ To use the processor, include a dependency on `spring-boot-configuration-process ...@@ -11,7 +11,7 @@ To use the processor, include a dependency on `spring-boot-configuration-process
With Maven the dependency should be declared as optional, as shown in the following example: With Maven the dependency should be declared as optional, as shown in the following example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -22,7 +22,7 @@ With Maven the dependency should be declared as optional, as shown in the follow ...@@ -22,7 +22,7 @@ With Maven the dependency should be declared as optional, as shown in the follow
With Gradle, the dependency should be declared in the `annotationProcessor` configuration, as shown in the following example: With Gradle, the dependency should be declared in the `annotationProcessor` configuration, as shown in the following example:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"] [source,gradle,indent=0,subs="verbatim"]
---- ----
dependencies { dependencies {
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
...@@ -31,7 +31,7 @@ With Gradle, the dependency should be declared in the `annotationProcessor` conf ...@@ -31,7 +31,7 @@ With Gradle, the dependency should be declared in the `annotationProcessor` conf
If you are using an `additional-spring-configuration-metadata.json` file, the `compileJava` task should be configured to depend on the `processResources` task, as shown in the following example: If you are using an `additional-spring-configuration-metadata.json` file, the `compileJava` task should be configured to depend on the `processResources` task, as shown in the following example:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"] [source,gradle,indent=0,subs="verbatim"]
---- ----
compileJava.inputs.files(processResources) compileJava.inputs.files(processResources)
---- ----
...@@ -45,7 +45,7 @@ There are several ways to do this. ...@@ -45,7 +45,7 @@ There are several ways to do this.
With Maven, you can configure the `maven-apt-plugin` explicitly and add the dependency to the annotation processor only there. With Maven, you can configure the `maven-apt-plugin` explicitly and add the dependency to the annotation processor only there.
You could also let the AspectJ plugin run all the processing and disable annotation processing in the `maven-compiler-plugin` configuration, as follows: You could also let the AspectJ plugin run all the processing and disable annotation processing in the `maven-compiler-plugin` configuration, as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
...@@ -69,7 +69,7 @@ The annotation processor also supports the use of the `@Data`, `@Getter`, and `@ ...@@ -69,7 +69,7 @@ The annotation processor also supports the use of the `@Data`, `@Getter`, and `@
Consider the following example: Consider the following example:
[source,java,indent=0,subs="verbatim,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/MyServerProperties.java[] include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/MyServerProperties.java[]
---- ----
...@@ -86,14 +86,14 @@ Also, the annotation processor cannot auto-detect default values for ``Enum``s a ...@@ -86,14 +86,14 @@ Also, the annotation processor cannot auto-detect default values for ``Enum``s a
For cases where the default value could not be detected, <<configuration-metadata#configuration-metadata.annotation-processor.adding-additional-metadata,manual metadata>> should be provided. For cases where the default value could not be detected, <<configuration-metadata#configuration-metadata.annotation-processor.adding-additional-metadata,manual metadata>> should be provided.
Consider the following example: Consider the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/MyMessagingProperties.java[] include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/MyMessagingProperties.java[]
---- ----
In order to document default values for properties in the class above, you could add the following content to <<configuration-metadata#configuration-metadata.annotation-processor.adding-additional-metadata,the manual metadata of the module>>: In order to document default values for properties in the class above, you could add the following content to <<configuration-metadata#configuration-metadata.annotation-processor.adding-additional-metadata,the manual metadata of the module>>:
[source,json,indent=0] [source,json,indent=0,subs="verbatim"]
---- ----
{"properties": [ {"properties": [
{ {
...@@ -117,7 +117,7 @@ The annotation processor automatically considers inner classes as nested propert ...@@ -117,7 +117,7 @@ The annotation processor automatically considers inner classes as nested propert
Rather than documenting the `ip` and `port` at the root of the namespace, we could create a sub-namespace for it. Rather than documenting the `ip` and `port` at the root of the namespace, we could create a sub-namespace for it.
Consider the updated example: Consider the updated example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/nestedproperties/MyServerProperties.java[] include::{docs-java}/configurationmetadata/annotationprocessor/automaticmetadatageneration/nestedproperties/MyServerProperties.java[]
---- ----
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Configuration metadata files are located inside jars under `META-INF/spring-configuration-metadata.json`. Configuration metadata files are located inside jars under `META-INF/spring-configuration-metadata.json`.
They use a JSON format with items categorized under either "`groups`" or "`properties`" and additional values hints categorized under "hints", as shown in the following example: They use a JSON format with items categorized under either "`groups`" or "`properties`" and additional values hints categorized under "hints", as shown in the following example:
[source,json,indent=0] [source,json,indent=0,subs="verbatim"]
---- ----
{"groups": [ {"groups": [
{ {
...@@ -68,7 +68,7 @@ They use a JSON format with items categorized under either "`groups`" or "`prope ...@@ -68,7 +68,7 @@ They use a JSON format with items categorized under either "`groups`" or "`prope
Each "`property`" is a configuration item that the user specifies with a given value. Each "`property`" is a configuration item that the user specifies with a given value.
For example, `server.port` and `server.address` might be specified in `application.properties`, as follows: For example, `server.port` and `server.address` might be specified in `application.properties`, as follows:
[source,properties,indent=0,configprops] [source,properties,indent=0,subs="verbatim",configprops]
---- ----
server.port=9090 server.port=9090
server.address=127.0.0.1 server.address=127.0.0.1
...@@ -207,7 +207,7 @@ Deprecation can also be specified declaratively in code by adding the `@Deprecat ...@@ -207,7 +207,7 @@ Deprecation can also be specified declaratively in code by adding the `@Deprecat
For instance, assume that the `my.app.target` property was confusing and was renamed to `my.app.name`. For instance, assume that the `my.app.target` property was confusing and was renamed to `my.app.name`.
The following example shows how to handle that situation: The following example shows how to handle that situation:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/configurationmetadata/format/group/MyProperties.java[] include::{docs-java}/configurationmetadata/format/group/MyProperties.java[]
---- ----
......
...@@ -18,7 +18,7 @@ The special `.keys` and `.values` suffixes must refer to the keys and the values ...@@ -18,7 +18,7 @@ The special `.keys` and `.values` suffixes must refer to the keys and the values
Assume a `my.contexts` maps magic `String` values to an integer, as shown in the following example: Assume a `my.contexts` maps magic `String` values to an integer, as shown in the following example:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/configurationmetadata/manualhints/valuehint/MyProperties.java[] include::{docs-java}/configurationmetadata/manualhints/valuehint/MyProperties.java[]
---- ----
...@@ -26,7 +26,7 @@ include::{docs-java}/configurationmetadata/manualhints/valuehint/MyProperties.ja ...@@ -26,7 +26,7 @@ include::{docs-java}/configurationmetadata/manualhints/valuehint/MyProperties.ja
The magic values are (in this example) are `sample1` and `sample2`. The magic values are (in this example) are `sample1` and `sample2`.
In order to offer additional content assistance for the keys, you could add the following JSON to <<configuration-metadata#configuration-metadata.annotation-processor.adding-additional-metadata,the manual metadata of the module>>: In order to offer additional content assistance for the keys, you could add the following JSON to <<configuration-metadata#configuration-metadata.annotation-processor.adding-additional-metadata,the manual metadata of the module>>:
[source,json,indent=0] [source,json,indent=0,subs="verbatim"]
---- ----
{"hints": [ {"hints": [
{ {
...@@ -101,7 +101,7 @@ This provider is typically used if you have a list of values and any extra value ...@@ -101,7 +101,7 @@ This provider is typically used if you have a list of values and any extra value
The following example offers `on` and `off` as auto-completion values for `system.state`: The following example offers `on` and `off` as auto-completion values for `system.state`:
[source,json,indent=0] [source,json,indent=0,subs="verbatim"]
---- ----
{"hints": [ {"hints": [
{ {
...@@ -152,7 +152,7 @@ This provider supports the following parameters: ...@@ -152,7 +152,7 @@ This provider supports the following parameters:
The following metadata snippet corresponds to the standard `server.servlet.jsp.class-name` property that defines the `JspServlet` class name to use: The following metadata snippet corresponds to the standard `server.servlet.jsp.class-name` property that defines the `JspServlet` class name to use:
[source,json,indent=0] [source,json,indent=0,subs="verbatim"]
---- ----
{"hints": [ {"hints": [
{ {
...@@ -202,7 +202,7 @@ TIP: If multiple values can be provided, use a `Collection` or _Array_ type to t ...@@ -202,7 +202,7 @@ TIP: If multiple values can be provided, use a `Collection` or _Array_ type to t
The following metadata snippet corresponds to the standard `spring.liquibase.change-log` property that defines the path to the changelog to use. The following metadata snippet corresponds to the standard `spring.liquibase.change-log` property that defines the path to the changelog to use.
It is actually used internally as a `org.springframework.core.io.Resource` but cannot be exposed as such, because we need to keep the original String value to pass it to the Liquibase API. It is actually used internally as a `org.springframework.core.io.Resource` but cannot be exposed as such, because we need to keep the original String value to pass it to the Liquibase API.
[source,json,indent=0] [source,json,indent=0,subs="verbatim"]
---- ----
{"hints": [ {"hints": [
{ {
...@@ -246,7 +246,7 @@ The following metadata snippet corresponds to the standard `logging.level` prope ...@@ -246,7 +246,7 @@ The following metadata snippet corresponds to the standard `logging.level` prope
Keys are _logger names_, and values correspond to the standard log levels or any custom level. Keys are _logger names_, and values correspond to the standard log levels or any custom level.
As Spring Boot defines a few logger groups out-of-the-box, dedicated value hints have been added for those. As Spring Boot defines a few logger groups out-of-the-box, dedicated value hints have been added for those.
[source,json,indent=0] [source,json,indent=0,subs="verbatim"]
---- ----
{"hints": [ {"hints": [
{ {
...@@ -326,7 +326,7 @@ This provider supports the following parameters: ...@@ -326,7 +326,7 @@ This provider supports the following parameters:
The following metadata snippet corresponds to the standard `spring.jmx.server` property that defines the name of the `MBeanServer` bean to use: The following metadata snippet corresponds to the standard `spring.jmx.server` property that defines the name of the `MBeanServer` bean to use:
[source,json,indent=0] [source,json,indent=0,subs="verbatim"]
---- ----
{"hints": [ {"hints": [
{ {
...@@ -354,7 +354,7 @@ The **spring-profile-name** provider auto-completes the Spring profiles that are ...@@ -354,7 +354,7 @@ The **spring-profile-name** provider auto-completes the Spring profiles that are
The following metadata snippet corresponds to the standard `spring.profiles.active` property that defines the name of the Spring profile(s) to enable: The following metadata snippet corresponds to the standard `spring.profiles.active` property that defines the name of the Spring profile(s) to enable:
[source,json,indent=0] [source,json,indent=0,subs="verbatim"]
---- ----
{"hints": [ {"hints": [
{ {
......
...@@ -27,7 +27,7 @@ Once you have built your application (by using, for example, `mvn clean package` ...@@ -27,7 +27,7 @@ Once you have built your application (by using, for example, `mvn clean package`
Be sure to have https://docs.cloudfoundry.org/cf-cli/getting-started.html#login[logged in with your `cf` command line client] before pushing an application. Be sure to have https://docs.cloudfoundry.org/cf-cli/getting-started.html#login[logged in with your `cf` command line client] before pushing an application.
The following line shows using the `cf push` command to deploy an application: The following line shows using the `cf push` command to deploy an application:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ cf push acloudyspringtime -p target/demo-0.0.1-SNAPSHOT.jar $ cf push acloudyspringtime -p target/demo-0.0.1-SNAPSHOT.jar
---- ----
...@@ -39,7 +39,7 @@ If there is a Cloud Foundry https://docs.cloudfoundry.org/devguide/deploy-apps/m ...@@ -39,7 +39,7 @@ If there is a Cloud Foundry https://docs.cloudfoundry.org/devguide/deploy-apps/m
At this point, `cf` starts uploading your application, producing output similar to the following example: At this point, `cf` starts uploading your application, producing output similar to the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim,quotes"]
---- ----
Uploading acloudyspringtime... *OK* Uploading acloudyspringtime... *OK*
Preparing to start acloudyspringtime... *OK* Preparing to start acloudyspringtime... *OK*
...@@ -68,7 +68,7 @@ Congratulations! The application is now live! ...@@ -68,7 +68,7 @@ Congratulations! The application is now live!
Once your application is live, you can verify the status of the deployed application by using the `cf apps` command, as shown in the following example: Once your application is live, you can verify the status of the deployed application by using the `cf apps` command, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ cf apps $ cf apps
Getting applications in ... Getting applications in ...
...@@ -93,7 +93,7 @@ Process-scoped environment variables are language agnostic. ...@@ -93,7 +93,7 @@ Process-scoped environment variables are language agnostic.
Environment variables do not always make for the easiest API, so Spring Boot automatically extracts them and flattens the data into properties that can be accessed through Spring's `Environment` abstraction, as shown in the following example: Environment variables do not always make for the easiest API, so Spring Boot automatically extracts them and flattens the data into properties that can be accessed through Spring's `Environment` abstraction, as shown in the following example:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/deployment/cloud/cloudfoundry/bindingtoservices/MyBean.java[] include::{docs-java}/deployment/cloud/cloudfoundry/bindingtoservices/MyBean.java[]
---- ----
...@@ -124,7 +124,7 @@ You can configure a sleep execution in a preStop handler to avoid requests being ...@@ -124,7 +124,7 @@ You can configure a sleep execution in a preStop handler to avoid requests being
This sleep should be long enough for new requests to stop being routed to the pod and its duration will vary from deployment to deployment. This sleep should be long enough for new requests to stop being routed to the pod and its duration will vary from deployment to deployment.
The preStop handler can be configured via the PodSpec in the pod's configuration file as follows: The preStop handler can be configured via the PodSpec in the pod's configuration file as follows:
[source,yml,indent=0] [source,yml,indent=0,subs="verbatim"]
---- ----
spec: spec:
containers: containers:
...@@ -161,7 +161,7 @@ The `$PORT` environment variable is assigned to us by the Heroku PaaS. ...@@ -161,7 +161,7 @@ The `$PORT` environment variable is assigned to us by the Heroku PaaS.
This should be everything you need. This should be everything you need.
The most common deployment workflow for Heroku deployments is to `git push` the code to production, as shown in the following example: The most common deployment workflow for Heroku deployments is to `git push` the code to production, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim,quotes"]
---- ----
$ git push heroku main $ git push heroku main
...@@ -270,7 +270,7 @@ By default, Elastic Beanstalk uploads sources and compiles them in AWS. ...@@ -270,7 +270,7 @@ By default, Elastic Beanstalk uploads sources and compiles them in AWS.
However, it is best to upload the binaries instead. However, it is best to upload the binaries instead.
To do so, add lines similar to the following to your `.elasticbeanstalk/config.yml` file: To do so, add lines similar to the following to your `.elasticbeanstalk/config.yml` file:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
deploy: deploy:
artifact: target/demo-0.0.1-SNAPSHOT.jar artifact: target/demo-0.0.1-SNAPSHOT.jar
...@@ -321,7 +321,7 @@ If your executable jar or war contains an https://boxfuse.com/docs/payloads/spri ...@@ -321,7 +321,7 @@ If your executable jar or war contains an https://boxfuse.com/docs/payloads/spri
At this point, `boxfuse` creates an image for your application, uploads it, and configures and starts the necessary resources on AWS, resulting in output similar to the following example: At this point, `boxfuse` creates an image for your application, uploads it, and configures and starts the necessary resources on AWS, resulting in output similar to the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
Fusing Image for myapp-1.0.jar ... Fusing Image for myapp-1.0.jar ...
Image fused in 00:06.838s (53937 K) -> axelfontaine/myapp:1.0 Image fused in 00:06.838s (53937 K) -> axelfontaine/myapp:1.0
...@@ -362,7 +362,7 @@ Follow https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/appe ...@@ -362,7 +362,7 @@ Follow https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/appe
Alternatively, App Engine Flex requires you to create an `app.yaml` file to describe the resources your app requires. Alternatively, App Engine Flex requires you to create an `app.yaml` file to describe the resources your app requires.
Normally, you put this file in `src/main/appengine`, and it should resemble the following file: Normally, you put this file in `src/main/appengine`, and it should resemble the following file:
[source,yaml,indent=0] [source,yaml,indent=0,subs="verbatim"]
---- ----
service: default service: default
...@@ -388,7 +388,7 @@ Normally, you put this file in `src/main/appengine`, and it should resemble the ...@@ -388,7 +388,7 @@ Normally, you put this file in `src/main/appengine`, and it should resemble the
You can deploy the app (for example, with a Maven plugin) by adding the project ID to the build configuration, as shown in the following example: You can deploy the app (for example, with a Maven plugin) by adding the project ID to the build configuration, as shown in the following example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<plugin> <plugin>
<groupId>com.google.cloud.tools</groupId> <groupId>com.google.cloud.tools</groupId>
......
...@@ -15,7 +15,7 @@ A standard-format jar file that contains one or more zip64-format nested jars ca ...@@ -15,7 +15,7 @@ A standard-format jar file that contains one or more zip64-format nested jars ca
To create a '`fully executable`' jar with Maven, use the following plugin configuration: To create a '`fully executable`' jar with Maven, use the following plugin configuration:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -28,7 +28,7 @@ To create a '`fully executable`' jar with Maven, use the following plugin config ...@@ -28,7 +28,7 @@ To create a '`fully executable`' jar with Maven, use the following plugin config
The following example shows the equivalent Gradle configuration: The following example shows the equivalent Gradle configuration:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"] [source,gradle,indent=0,subs="verbatim"]
---- ----
bootJar { bootJar {
launchScript() launchScript()
...@@ -66,7 +66,7 @@ The script supports the following features: ...@@ -66,7 +66,7 @@ The script supports the following features:
Assuming that you have a Spring Boot application installed in `/var/myapp`, to install a Spring Boot application as an `init.d` service, create a symlink, as follows: Assuming that you have a Spring Boot application installed in `/var/myapp`, to install a Spring Boot application as an `init.d` service, create a symlink, as follows:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp $ sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp
---- ----
...@@ -74,7 +74,7 @@ Assuming that you have a Spring Boot application installed in `/var/myapp`, to i ...@@ -74,7 +74,7 @@ Assuming that you have a Spring Boot application installed in `/var/myapp`, to i
Once installed, you can start and stop the service in the usual way. Once installed, you can start and stop the service in the usual way.
For example, on a Debian-based system, you could start it with the following command: For example, on a Debian-based system, you could start it with the following command:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ service myapp start $ service myapp start
---- ----
...@@ -84,7 +84,7 @@ TIP: If your application fails to start, check the log file written to `/var/log ...@@ -84,7 +84,7 @@ TIP: If your application fails to start, check the log file written to `/var/log
You can also flag the application to start automatically by using your standard operating system tools. You can also flag the application to start automatically by using your standard operating system tools.
For example, on Debian, you could use the following command: For example, on Debian, you could use the following command:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ update-rc.d myapp defaults <priority> $ update-rc.d myapp defaults <priority>
---- ----
...@@ -101,7 +101,7 @@ When the environment variable is not set, the user who owns the jar file is used ...@@ -101,7 +101,7 @@ When the environment variable is not set, the user who owns the jar file is used
You should never run a Spring Boot application as `root`, so `RUN_AS_USER` should never be root and your application's jar file should never be owned by root. You should never run a Spring Boot application as `root`, so `RUN_AS_USER` should never be root and your application's jar file should never be owned by root.
Instead, create a specific user to run your application and set the `RUN_AS_USER` environment variable or use `chown` to make it the owner of the jar file, as shown in the following example: Instead, create a specific user to run your application and set the `RUN_AS_USER` environment variable or use `chown` to make it the owner of the jar file, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ chown bootapp:bootapp your-app.jar $ chown bootapp:bootapp your-app.jar
---- ----
...@@ -114,7 +114,7 @@ For example, you can set the account's shell to `/usr/sbin/nologin`. ...@@ -114,7 +114,7 @@ For example, you can set the account's shell to `/usr/sbin/nologin`.
You should also take steps to prevent the modification of your application's jar file. You should also take steps to prevent the modification of your application's jar file.
Firstly, configure its permissions so that it cannot be written and can only be read or executed by its owner, as shown in the following example: Firstly, configure its permissions so that it cannot be written and can only be read or executed by its owner, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ chmod 500 your-app.jar $ chmod 500 your-app.jar
---- ----
...@@ -123,7 +123,7 @@ Second, you should also take steps to limit the damage if your application or th ...@@ -123,7 +123,7 @@ Second, you should also take steps to limit the damage if your application or th
If an attacker does gain access, they could make the jar file writable and change its contents. If an attacker does gain access, they could make the jar file writable and change its contents.
One way to protect against this is to make it immutable by using `chattr`, as shown in the following example: One way to protect against this is to make it immutable by using `chattr`, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ sudo chattr +i your-app.jar $ sudo chattr +i your-app.jar
---- ----
...@@ -134,7 +134,7 @@ If root is used to control the application's service and you <<deployment#deploy ...@@ -134,7 +134,7 @@ If root is used to control the application's service and you <<deployment#deploy
It should be secured accordingly. It should be secured accordingly.
Use `chmod` so that the file can only be read by the owner and use `chown` to make root the owner, as shown in the following example: Use `chmod` so that the file can only be read by the owner and use `chown` to make root the owner, as shown in the following example:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ chmod 400 your-app.conf $ chmod 400 your-app.conf
$ sudo chown root:root your-app.conf $ sudo chown root:root your-app.conf
...@@ -174,7 +174,7 @@ Consult the https://www.freedesktop.org/software/systemd/man/systemd.service.htm ...@@ -174,7 +174,7 @@ Consult the https://www.freedesktop.org/software/systemd/man/systemd.service.htm
To flag the application to start automatically on system boot, use the following command: To flag the application to start automatically on system boot, use the following command:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ systemctl enable myapp.service $ systemctl enable myapp.service
---- ----
...@@ -370,7 +370,7 @@ The file is expected to be next to the jar file and have the same name but suffi ...@@ -370,7 +370,7 @@ The file is expected to be next to the jar file and have the same name but suffi
For example, a jar named `/var/myapp/myapp.jar` uses the configuration file named `/var/myapp/myapp.conf`, as shown in the following example: For example, a jar named `/var/myapp/myapp.jar` uses the configuration file named `/var/myapp/myapp.conf`, as shown in the following example:
.myapp.conf .myapp.conf
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
JAVA_OPTS=-Xmx1024M JAVA_OPTS=-Xmx1024M
LOG_FOLDER=/custom/log/folder LOG_FOLDER=/custom/log/folder
......
...@@ -9,7 +9,7 @@ NOTE: Check the {spring-framework-docs}/integration.html#cache[relevant section] ...@@ -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: 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[] include::{docs-java}/features/caching/MyMathService.java[]
---- ----
...@@ -59,7 +59,7 @@ If you add dependencies manually, you must include `spring-context-support` in o ...@@ -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. 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: 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[] include::{docs-java}/features/caching/provider/MyCacheManagerConfiguration.java[]
---- ----
...@@ -86,7 +86,7 @@ Any other compliant library can be added as well. ...@@ -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. 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: 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 # Only necessary if more than one provider is present
spring: spring:
...@@ -118,7 +118,7 @@ https://www.ehcache.org/[EhCache] 2.x is used if a file named `ehcache.xml` can ...@@ -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. 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: 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: spring:
cache: cache:
...@@ -140,7 +140,7 @@ If a `HazelcastInstance` has been auto-configured, it is automatically wrapped i ...@@ -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. https://infinispan.org/[Infinispan] has no default configuration file location, so it must be specified explicitly.
Otherwise, the default bootstrap is used. Otherwise, the default bootstrap is used.
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
cache: cache:
...@@ -163,7 +163,7 @@ If Spring Data Couchbase is available and Couchbase is <<features#features.nosql ...@@ -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. 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: 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: spring:
cache: cache:
...@@ -175,7 +175,7 @@ For instance, the following configuration creates `cache1` and `cache2` caches w ...@@ -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. 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`: 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[] 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 ...@@ -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. 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: 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: spring:
cache: cache:
...@@ -206,7 +206,7 @@ This can be useful if you're looking for customizing the default serialization s ...@@ -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. 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`: 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[] 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 ...@@ -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 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: spring:
cache: cache:
...@@ -247,7 +247,7 @@ This is the default if no caching library is present in your application. ...@@ -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. 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: 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: spring:
cache: cache:
...@@ -264,7 +264,7 @@ This is similar to the way the "real" cache providers behave if you use an undec ...@@ -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. 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: 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: spring:
cache: cache:
......
...@@ -23,7 +23,7 @@ Out-of-the-box, the following layers are supported: ...@@ -23,7 +23,7 @@ Out-of-the-box, the following layers are supported:
The following shows an example of a `layers.idx` file: The following shows an example of a `layers.idx` file:
[source,yaml,indent=0] [source,yaml,indent=0,subs="verbatim"]
---- ----
- "dependencies": - "dependencies":
- BOOT-INF/lib/library1.jar - BOOT-INF/lib/library1.jar
......
...@@ -76,7 +76,7 @@ This mechanism does not apply the same way to `@Bean` methods where typically th ...@@ -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: 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[] include::{docs-java}/features/developingautoconfiguration/conditionannotations/classconditions/MyAutoConfiguration.java[]
---- ----
...@@ -93,7 +93,7 @@ The `search` attribute lets you limit the `ApplicationContext` hierarchy that sh ...@@ -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: 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[] include::{docs-java}/features/developingautoconfiguration/conditionannotations/beanconditions/MyAutoConfiguration.java[]
---- ----
...@@ -154,7 +154,7 @@ Concretely, each test should create a well defined `ApplicationContext` that rep ...@@ -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. `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: 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] 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. ...@@ -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. For instance, the sample below invokes a user configuration (`UserConfiguration`) and checks that the auto-configuration backs off properly.
Invoking `run` provides a callback context that can be used with `AssertJ`. Invoking `run` provides a callback context that can be used with `AssertJ`.
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/features/developingautoconfiguration/testing/MyServiceAutoConfigurationTests.java[tag=test-user-config] 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: 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] 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`. ...@@ -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 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. 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[] 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 ...@@ -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. 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: 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] 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 ...@@ -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: 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[] 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 ...@@ -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. 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: 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> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -293,7 +293,7 @@ It is recommended to add the following dependency in a module that contains auto ...@@ -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: 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> <project>
<build> <build>
...@@ -317,7 +317,7 @@ If you have defined auto-configurations directly in your application, make sure ...@@ -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: 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 { dependencies {
compileOnly "org.springframework.boot:spring-boot-autoconfigure-processor" 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 ...@@ -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: 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 { dependencies {
annotationProcessor "org.springframework.boot:spring-boot-autoconfigure-processor" annotationProcessor "org.springframework.boot:spring-boot-autoconfigure-processor"
......
...@@ -10,7 +10,7 @@ See {spring-boot-autoconfigure-module-code}/mail/MailProperties.java[`MailProper ...@@ -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: 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: spring:
mail: mail:
...@@ -22,7 +22,7 @@ In particular, certain default timeout values are infinite, and you may want to ...@@ -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: 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: spring:
mail: mail:
......
...@@ -11,7 +11,7 @@ NOTE: Graceful shutdown with Tomcat requires Tomcat 9.0.33 or later. ...@@ -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: 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: server:
shutdown: "graceful" shutdown: "graceful"
...@@ -19,7 +19,7 @@ server: ...@@ -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: 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: spring:
lifecycle: lifecycle:
......
...@@ -19,7 +19,7 @@ If your configuration defines an instance name, Spring Boot tries to locate an e ...@@ -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: 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: spring:
hazelcast: hazelcast:
......
...@@ -9,7 +9,7 @@ If no properties file is found that matches any of the configured base names, th ...@@ -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: 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: spring:
messages: messages:
......
...@@ -41,7 +41,7 @@ Spring Boot tries to auto-configure JMS by looking for a `ConnectionFactory` at ...@@ -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. 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`: 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=*] 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. ...@@ -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: 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=*] include::{docs-java}/features/jta/mixingxaandnonxaconnections/nonxa/MyBean.java[tag=*]
---- ----
For consistency, the `jmsConnectionFactory` bean is also provided by using the bean alias `xaJmsConnectionFactory`: 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=*] include::{docs-java}/features/jta/mixingxaandnonxaconnections/xa/MyBean.java[tag=*]
---- ----
......
...@@ -57,7 +57,7 @@ Also be aware that Spring Boot's own API is {github-issues}10712[not yet annotat ...@@ -57,7 +57,7 @@ Also be aware that Spring Boot's own API is {github-issues}10712[not yet annotat
==== runApplication ==== runApplication
Spring Boot provides an idiomatic way to run an application with `runApplication<MyApplication>(*args)` as shown in the following example: 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.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication import org.springframework.boot.runApplication
...@@ -73,7 +73,7 @@ Spring Boot provides an idiomatic way to run an application with `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)`. 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: 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) { runApplication<MyApplication>(*args) {
setBannerMode(OFF) setBannerMode(OFF)
...@@ -110,7 +110,7 @@ TIP: `org.jetbrains.kotlinx:kotlinx-coroutines-reactor` dependency is provided b ...@@ -110,7 +110,7 @@ TIP: `org.jetbrains.kotlinx:kotlinx-coroutines-reactor` dependency is provided b
=== @ConfigurationProperties === @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: `@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 @ConstructorBinding
@ConfigurationProperties("example.kotlin") @ConfigurationProperties("example.kotlin")
......
...@@ -73,7 +73,7 @@ You can set `spring.output.ansi.enabled` to a {spring-boot-module-api}/ansi/Ansi ...@@ -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. 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: 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) %clr(%5p)
---- ----
...@@ -105,7 +105,7 @@ The following table describes the mapping of log levels to colors: ...@@ -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. 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: 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} %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`. ...@@ -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`: 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 .Properties
---- ----
logging.level.root=warn logging.level.root=warn
...@@ -202,7 +202,7 @@ The following example shows potential logging settings in `application.propertie ...@@ -202,7 +202,7 @@ The following example shows potential logging settings in `application.propertie
logging.level.org.hibernate=error logging.level.org.hibernate=error
---- ----
[source,properties,indent=0,subs="verbatim,quotes,attributes",role="secondary"] [source,properties,indent=0,subs="verbatim",role="secondary"]
.Yaml .Yaml
---- ----
logging: logging:
...@@ -229,7 +229,7 @@ For example, you might commonly change the logging levels for _all_ Tomcat relat ...@@ -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`. 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`: 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: logging:
group: group:
...@@ -238,7 +238,7 @@ For example, here's how you could define a "`tomcat`" group by adding it to your ...@@ -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: 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: logging:
level: level:
...@@ -271,7 +271,7 @@ You can use the configprop:logging.register-shutdown-hook[] property to disable ...@@ -271,7 +271,7 @@ You can use the configprop:logging.register-shutdown-hook[] property to disable
Setting it to `false` will disable the registration. Setting it to `false` will disable the registration.
You can set the property in your `application.properties` or `application.yaml` file: 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: logging:
register-shutdown-hook: false register-shutdown-hook: false
...@@ -440,7 +440,7 @@ A profile expression allows for more complicated profile logic to be expressed, ...@@ -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. Check the {spring-framework-docs}/core.html#beans-definition-profiles-java[reference guide] for more details.
The following listing shows three sample profiles: The following listing shows three sample profiles:
[source,xml,indent=0] [source,xml,subs="verbatim",indent=0]
---- ----
<springProfile name="staging"> <springProfile name="staging">
<!-- configuration to be enabled when the "staging" profile is active --> <!-- 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 ...@@ -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. 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: 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" <springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
defaultValue="localhost"/> defaultValue="localhost"/>
......
...@@ -15,7 +15,7 @@ You can use a configprop:spring.profiles.active[] `Environment` property to spec ...@@ -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. 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: 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: spring:
profiles: profiles:
...@@ -48,7 +48,7 @@ A profile group allows you to define a logical name for a related group of profi ...@@ -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. 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: spring:
profiles: profiles:
......
...@@ -13,7 +13,7 @@ Beans of the following types are automatically picked up and associated with the ...@@ -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. 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: 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: spring:
quartz: quartz:
...@@ -22,7 +22,7 @@ However, it is possible to configure a JDBC-based store if a `DataSource` bean i ...@@ -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: 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: spring:
quartz: quartz:
...@@ -50,7 +50,7 @@ If you need to customize the task executor, consider implementing `SchedulerFact ...@@ -50,7 +50,7 @@ If you need to customize the task executor, consider implementing `SchedulerFact
Jobs can define setters to inject data map properties. 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: 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[] include::{docs-java}/features/quartz/MySampleJob.java[]
---- ----
...@@ -7,7 +7,7 @@ The auto-configured `RestTemplateBuilder` ensures that sensible `HttpMessageConv ...@@ -7,7 +7,7 @@ The auto-configured `RestTemplateBuilder` ensures that sensible `HttpMessageConv
The following code shows a typical example: The following code shows a typical example:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/features/resttemplate/MyService.java[] include::{docs-java}/features/resttemplate/MyService.java[]
---- ----
...@@ -29,7 +29,7 @@ All such beans are automatically registered with the auto-configured `RestTempla ...@@ -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`: 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[] include::{docs-java}/features/resttemplate/customization/MyRestTemplateCustomizer.java[]
---- ----
...@@ -38,7 +38,7 @@ Finally, you can also create your own `RestTemplateBuilder` bean. ...@@ -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`. 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: 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[] include::{docs-java}/features/resttemplate/customization/MyRestTemplateBuilderConfiguration.java[]
---- ----
......
...@@ -35,7 +35,7 @@ This depends on the type of application and its configuration. ...@@ -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: 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: spring:
rsocket: rsocket:
...@@ -49,7 +49,7 @@ WARNING: Plugging RSocket into a web server is only supported with Reactor Netty ...@@ -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. 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: 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: spring:
rsocket: rsocket:
...@@ -80,7 +80,7 @@ This is done on purpose since this builder is stateful and you shouldn't create ...@@ -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: 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[] include::{docs-java}/features/rsocket//requester/MyService.java[]
---- ----
...@@ -60,7 +60,7 @@ Spring Boot provides convenience methods that can be used to override access rul ...@@ -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: 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[] include::{docs-java}/features/security/springwebflux/MyWebFluxSecurityConfiguration.java[]
---- ----
...@@ -81,7 +81,7 @@ The same properties are applicable to both servlet and reactive applications. ...@@ -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: 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: spring:
security: security:
...@@ -124,7 +124,7 @@ For example, if the `issuer-uri` provided is "https://example.com", then an `Ope ...@@ -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 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`: 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: spring:
security: security:
...@@ -139,7 +139,7 @@ By default, Spring Security's `OAuth2LoginAuthenticationFilter` only processes U ...@@ -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. 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: 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[] 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 ...@@ -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: 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: spring:
security: security:
...@@ -182,7 +182,7 @@ In other words, the two configurations in the following example use the Google p ...@@ -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. 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: 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: spring:
security: security:
...@@ -192,7 +192,7 @@ For JWT configuration, a JWK Set URI or OIDC Issuer URI needs to be specified, a ...@@ -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" 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: spring:
security: security:
...@@ -211,7 +211,7 @@ Alternatively, you can define your own `JwtDecoder` bean for servlet application ...@@ -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: 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: spring:
security: security:
...@@ -250,7 +250,7 @@ This configuration makes use of the properties under `Saml2RelyingPartyPropertie ...@@ -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. 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: 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: spring:
security: security:
......
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
The `SpringApplication` class provides a convenient way to bootstrap a Spring application that is started from a `main()` method. 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: 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[] include::{docs-java}/features/springapplication/MyApplication.java[]
---- ----
When your application starts, you should see something similar to the following output: 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 ...@@ -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: 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 $ 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 ...@@ -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`. 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: 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: spring:
main: main:
...@@ -165,7 +165,7 @@ This will initialize the `application.*` banner variables before building the cl ...@@ -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. 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: 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[] include::{docs-java}/features/springapplication/customizingspringapplication/MyApplication.java[]
---- ----
...@@ -186,7 +186,7 @@ If you need to build an `ApplicationContext` hierarchy (multiple contexts with a ...@@ -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: 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=*] 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 ...@@ -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: 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[] 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: 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[] include::{docs-java}/features/springapplication/applicationavailability/managing/MyLocalCacheVerifier.java[]
---- ----
...@@ -332,7 +332,7 @@ TIP: It is often desirable to call `setWebApplicationType(WebApplicationType.NON ...@@ -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. 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: 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[] 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 ...@@ -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 `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: 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[] include::{docs-java}/features/springapplication/commandlinerunner/MyCommandLineRunner.java[]
---- ----
...@@ -370,7 +370,7 @@ All the standard Spring lifecycle callbacks (such as the `DisposableBean` interf ...@@ -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. 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: 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[] 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 ...@@ -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. You can choose an `ApplicationStartup` implementation when setting up the `SpringApplication` instance.
For example, to use the `BufferingApplicationStartup`, you could write: 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[] include::{docs-java}/features/springapplication/startuptracking/MyApplication.java[]
---- ----
...@@ -410,7 +410,7 @@ The first available implementation, `FlightRecorderApplicationStartup` is provid ...@@ -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...). 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: 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 $ java -XX:StartFlightRecording:filename=recording.jfr,duration=10s -jar demo.jar
---- ----
......
...@@ -10,7 +10,7 @@ Spring Boot also configures some features that are triggered by the presence of ...@@ -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-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: 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: spring:
integration: integration:
...@@ -23,7 +23,7 @@ This infrastructure can handle Spring Integration RSocket channel adapters and ` ...@@ -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: 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 # Connecting to a RSocket server over TCP
spring: spring:
...@@ -34,7 +34,7 @@ Spring Boot can also auto-configure an `ClientRSocketConnector` using configurat ...@@ -34,7 +34,7 @@ Spring Boot can also auto-configure an `ClientRSocketConnector` using configurat
port: 9898 port: 9898
---- ----
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
# Connecting to a RSocket Server over WebSocket # Connecting to a RSocket Server over WebSocket
spring: spring:
......
...@@ -21,7 +21,7 @@ If a single Spring Session module is present on the classpath, Spring Boot uses ...@@ -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. 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: 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: spring:
session: session:
...@@ -33,7 +33,7 @@ TIP: You can disable Spring Session by setting the `store-type` to `none`. ...@@ -33,7 +33,7 @@ TIP: You can disable Spring Session by setting the `store-type` to `none`.
Each store has specific additional settings. 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: 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: spring:
session: session:
......
...@@ -36,7 +36,7 @@ If you want to make sure that each context has a separate embedded database, you ...@@ -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: For example, the typical POM dependencies would be as follows:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -70,7 +70,7 @@ Production database connections can also be auto-configured by using a pooling ` ...@@ -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.*+`. DataSource configuration is controlled by external configuration properties in `+spring.datasource.*+`.
For example, you might declare the following section in `application.properties`: 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: spring:
datasource: datasource:
...@@ -95,7 +95,7 @@ Refer to the documentation of the connection pool implementation you are using f ...@@ -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: 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: spring:
datasource: datasource:
...@@ -145,7 +145,7 @@ If you deploy your Spring Boot application to an Application Server, you might w ...@@ -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. 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`: 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: spring:
datasource: datasource:
...@@ -158,14 +158,14 @@ For example, the following section in `application.properties` shows how you can ...@@ -158,14 +158,14 @@ For example, the following section in `application.properties` shows how you can
=== Using JdbcTemplate === 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: 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[] 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: 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: spring:
jdbc: jdbc:
...@@ -202,7 +202,7 @@ By default, all packages below your main configuration class (the one annotated ...@@ -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. Any classes annotated with `@Entity`, `@Embeddable`, or `@MappedSuperclass` are considered.
A typical entity class resembles the following example: 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[] 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 ...@@ -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: 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[] 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 ...@@ -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. 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: The following listing shows an example:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<plugin> <plugin>
<groupId>org.jooq</groupId> <groupId>org.jooq</groupId>
...@@ -366,7 +366,7 @@ The fluent API offered by jOOQ is initiated through the `org.jooq.DSLContext` in ...@@ -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`. 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: 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] 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 ...@@ -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: 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] 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 ...@@ -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.*+`. `ConnectionFactory` configuration is controlled by external configuration properties in `+spring.r2dbc.*+`.
For example, you might declare the following section in `application.properties`: 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: spring:
r2dbc: r2dbc:
...@@ -428,14 +428,14 @@ TIP: The "`How-to`" section includes a <<howto#howto.data-initialization.using-b ...@@ -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`. 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: 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[] include::{docs-java}/features/sql/r2dbc/MyR2dbcConfiguration.java[]
---- ----
The following examples show how to set some PostgreSQL connection options: 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[] include::{docs-java}/features/sql/r2dbc/MyPostgresR2dbcConfiguration.java[]
---- ----
...@@ -451,7 +451,7 @@ Similarly to <<features#features.sql.datasource.embedded,the JDBC support>>, Spr ...@@ -451,7 +451,7 @@ Similarly to <<features#features.sql.datasource.embedded,the JDBC support>>, Spr
You need not provide any connection URLs. 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: 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> <dependency>
<groupId>io.r2dbc</groupId> <groupId>io.r2dbc</groupId>
...@@ -472,7 +472,7 @@ If you want to make sure that each context has a separate embedded database, you ...@@ -472,7 +472,7 @@ If you want to make sure that each context has a separate embedded database, you
==== Using DatabaseClient ==== Using DatabaseClient
A `DatabaseClient` bean is auto-configured, and you can `@Autowire` it directly into your own beans, as shown in the following example: 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[] 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 ...@@ -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: 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[] include::{docs-java}/features/sql/r2dbc/repositories/CityRepository.java[]
---- ----
......
...@@ -13,7 +13,7 @@ The auto-configured `TaskExecutorBuilder` allows you to easily create instances ...@@ -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. 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: 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: spring:
task: task:
...@@ -30,7 +30,7 @@ Shrinking of the pool is more aggressive as threads are reclaimed when they are ...@@ -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`). 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: 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: spring:
task: task:
......
...@@ -6,7 +6,7 @@ Target classes with such annotated methods need to be annotated with the `@Valid ...@@ -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: 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[] include::{docs-java}/features/validation/MyBean.java[]
---- ----
...@@ -9,7 +9,7 @@ Spring Boot is configuring that builder to share HTTP resources, reflect codecs ...@@ -9,7 +9,7 @@ Spring Boot is configuring that builder to share HTTP resources, reflect codecs
The following code shows a typical example: The following code shows a typical example:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/features/webclient/MyService.java[] include::{docs-java}/features/webclient/MyService.java[]
---- ----
......
...@@ -8,7 +8,7 @@ The {spring-webservices-docs}[Spring Web Services features] can be easily access ...@@ -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: 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: spring:
webservices: webservices:
...@@ -25,7 +25,7 @@ It does, however, auto-configure a `WebServiceTemplateBuilder`, which can be use ...@@ -25,7 +25,7 @@ It does, however, auto-configure a `WebServiceTemplateBuilder`, which can be use
The following code shows a typical example: 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[] include::{docs-java}/features/webservices/template/MyService.java[]
---- ----
...@@ -33,7 +33,7 @@ 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. 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: 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[] include::{docs-java}/features/webservices/template/MyWebServiceTemplateConfiguration.java[]
---- ----
...@@ -7,7 +7,7 @@ Spring Framework provides {spring-framework-docs}/web.html#websocket[rich WebSoc ...@@ -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`: 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> <dependency>
<groupId>javax.websocket</groupId> <groupId>javax.websocket</groupId>
......
...@@ -42,7 +42,7 @@ We need to start by creating a Maven `pom.xml` file. ...@@ -42,7 +42,7 @@ We need to start by creating a Maven `pom.xml` file.
The `pom.xml` is the recipe that is used to build your project. The `pom.xml` is the recipe that is used to build your project.
Open your favorite text editor and add the following: Open your favorite text editor and add the following:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim,attributes"]
---- ----
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
...@@ -130,7 +130,7 @@ The `mvn dependency:tree` command prints a tree representation of your project d ...@@ -130,7 +130,7 @@ The `mvn dependency:tree` command prints a tree representation of your project d
You can see that `spring-boot-starter-parent` provides no dependencies by itself. You can see that `spring-boot-starter-parent` provides no dependencies by itself.
To add the necessary dependencies, edit your `pom.xml` and add the `spring-boot-starter-web` dependency immediately below the `parent` section: To add the necessary dependencies, edit your `pom.xml` and add the `spring-boot-starter-web` dependency immediately below the `parent` section:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependencies> <dependencies>
<dependency> <dependency>
...@@ -149,7 +149,7 @@ If you run `mvn dependency:tree` again, you see that there are now a number of a ...@@ -149,7 +149,7 @@ If you run `mvn dependency:tree` again, you see that there are now a number of a
To finish our application, we need to create a single Java file. To finish our application, we need to create a single Java file.
By default, Maven compiles sources from `src/main/java`, so you need to create that directory structure and then add a file named `src/main/java/MyApplication.java` to contain the following code: By default, Maven compiles sources from `src/main/java`, so you need to create that directory structure and then add a file named `src/main/java/MyApplication.java` to contain the following code:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/gettingstarted/firstapplication/code/MyApplication.java[] include::{docs-java}/gettingstarted/firstapplication/code/MyApplication.java[]
---- ----
...@@ -208,7 +208,7 @@ Since you used the `spring-boot-starter-parent` POM, you have a useful `run` goa ...@@ -208,7 +208,7 @@ Since you used the `spring-boot-starter-parent` POM, you have a useful `run` goa
Type `mvn spring-boot:run` from the root project directory to start the application. Type `mvn spring-boot:run` from the root project directory to start the application.
You should see output similar to the following: You should see output similar to the following:
[indent=0,subs="attributes"] [indent=0,subs="verbatim,attributes"]
---- ----
$ mvn spring-boot:run $ mvn spring-boot:run
...@@ -257,7 +257,7 @@ Spring Boot takes a <<executable-jar#executable-jar, different approach>> and le ...@@ -257,7 +257,7 @@ Spring Boot takes a <<executable-jar#executable-jar, different approach>> and le
To create an executable jar, we need to add the `spring-boot-maven-plugin` to our `pom.xml`. To create an executable jar, we need to add the `spring-boot-maven-plugin` to our `pom.xml`.
To do so, insert the following lines just below the `dependencies` section: To do so, insert the following lines just below the `dependencies` section:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<build> <build>
<plugins> <plugins>
...@@ -275,7 +275,7 @@ See the {spring-boot-maven-plugin-docs}#getting-started[plugin documentation] fo ...@@ -275,7 +275,7 @@ See the {spring-boot-maven-plugin-docs}#getting-started[plugin documentation] fo
Save your `pom.xml` and run `mvn package` from the command line, as follows: Save your `pom.xml` and run `mvn package` from the command line, as follows:
[indent=0,subs="attributes"] [indent=0,subs="verbatim,attributes"]
---- ----
$ mvn package $ mvn package
...@@ -308,7 +308,7 @@ This is the original jar file that Maven created before it was repackaged by Spr ...@@ -308,7 +308,7 @@ This is the original jar file that Maven created before it was repackaged by Spr
To run that application, use the `java -jar` command, as follows: To run that application, use the `java -jar` command, as follows:
[indent=0,subs="attributes"] [indent=0,subs="verbatim,attributes"]
---- ----
$ java -jar target/myproject-0.0.1-SNAPSHOT.jar $ java -jar target/myproject-0.0.1-SNAPSHOT.jar
......
...@@ -93,7 +93,7 @@ Alternatively, you can use `java -jar` with the `.jar` file (the script helps yo ...@@ -93,7 +93,7 @@ Alternatively, you can use `java -jar` with the `.jar` file (the script helps yo
SDKMAN! (The Software Development Kit Manager) can be used for managing multiple versions of various binary SDKs, including Groovy and the Spring Boot CLI. SDKMAN! (The Software Development Kit Manager) can be used for managing multiple versions of various binary SDKs, including Groovy and the Spring Boot CLI.
Get SDKMAN! from https://sdkman.io and install Spring Boot by using the following commands: Get SDKMAN! from https://sdkman.io and install Spring Boot by using the following commands:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim,attributes"]
---- ----
$ sdk install springboot $ sdk install springboot
$ spring --version $ spring --version
...@@ -102,7 +102,7 @@ Get SDKMAN! from https://sdkman.io and install Spring Boot by using the followin ...@@ -102,7 +102,7 @@ Get SDKMAN! from https://sdkman.io and install Spring Boot by using the followin
If you develop features for the CLI and want access to the version you built, use the following commands: If you develop features for the CLI and want access to the version you built, use the following commands:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim,attributes"]
---- ----
$ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-{spring-boot-version}-bin/spring-{spring-boot-version}/ $ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-{spring-boot-version}-bin/spring-{spring-boot-version}/
$ sdk default springboot dev $ sdk default springboot dev
...@@ -115,7 +115,7 @@ It points at your target build location, so every time you rebuild Spring Boot, ...@@ -115,7 +115,7 @@ It points at your target build location, so every time you rebuild Spring Boot,
You can see it by running the following command: You can see it by running the following command:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim,attributes"]
---- ----
$ sdk ls springboot $ sdk ls springboot
...@@ -202,7 +202,7 @@ In that case, run `scoop update` and try again. ...@@ -202,7 +202,7 @@ In that case, run `scoop update` and try again.
You can use the following web application to test your installation. You can use the following web application to test your installation.
To start, create a file called `app.groovy`, as follows: To start, create a file called `app.groovy`, as follows:
[source,groovy,indent=0,subs="verbatim,quotes,attributes"] [source,groovy,indent=0,pending-extract=true,subs="verbatim"]
---- ----
@RestController @RestController
class ThisWillActuallyRun { class ThisWillActuallyRun {
...@@ -244,7 +244,7 @@ When upgrading to a new feature release, some properties may have been renamed o ...@@ -244,7 +244,7 @@ When upgrading to a new feature release, some properties may have been renamed o
Spring Boot provides a way to analyze your application's environment and print diagnostics at startup, but also temporarily migrate properties at runtime for you. Spring Boot provides a way to analyze your application's environment and print diagnostics at startup, but also temporarily migrate properties at runtime for you.
To enable that feature, add the following dependency to your project: To enable that feature, add the following dependency to your project:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
......
...@@ -66,7 +66,7 @@ To export these, you'll need to convert these states to some set of numbers so t ...@@ -66,7 +66,7 @@ To export these, you'll need to convert these states to some set of numbers so t
The following example shows one way to write such an exporter: The following example shows one way to write such an exporter:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/actuator/maphealthindicatorstometrics/MyHealthMetricsExportConfiguration.java[] include::{docs-java}/howto/actuator/maphealthindicatorstometrics/MyHealthMetricsExportConfiguration.java[]
---- ----
...@@ -17,7 +17,7 @@ If, for whatever reason, you cannot handle the exception, return `null` to give ...@@ -17,7 +17,7 @@ If, for whatever reason, you cannot handle the exception, return `null` to give
`FailureAnalyzer` implementations must be registered in `META-INF/spring.factories`. `FailureAnalyzer` implementations must be registered in `META-INF/spring.factories`.
The following example registers `ProjectConstraintViolationFailureAnalyzer`: The following example registers `ProjectConstraintViolationFailureAnalyzer`:
[source,properties,indent=0] [source,properties,indent=0,subs="verbatim"]
---- ----
org.springframework.boot.diagnostics.FailureAnalyzer=\ org.springframework.boot.diagnostics.FailureAnalyzer=\
com.example.ProjectConstraintViolationFailureAnalyzer com.example.ProjectConstraintViolationFailureAnalyzer
...@@ -78,7 +78,7 @@ Each implementation should be registered in `META-INF/spring.factories`, as show ...@@ -78,7 +78,7 @@ Each implementation should be registered in `META-INF/spring.factories`, as show
The implementation can load arbitrary files and add them to the `Environment`. The implementation can load arbitrary files and add them to the `Environment`.
For instance, the following example loads a YAML configuration file from the classpath: For instance, the following example loads a YAML configuration file from the classpath:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/application/customizetheenvironmentorapplicationcontext/MyEnvironmentPostProcessor.java[] include::{docs-java}/howto/application/customizetheenvironmentorapplicationcontext/MyEnvironmentPostProcessor.java[]
---- ----
......
...@@ -35,7 +35,7 @@ Spring Boot converts any command line argument starting with `--` to a property ...@@ -35,7 +35,7 @@ Spring Boot converts any command line argument starting with `--` to a property
This should not be used to pass arguments to batch jobs. This should not be used to pass arguments to batch jobs.
To specify batch arguments on the command line, use the regular format (i.e. without `--`), as shown in the following example: To specify batch arguments on the command line, use the regular format (i.e. without `--`), as shown in the following example:
[indent=0,subs="attributes"] [indent=0,subs="verbatim"]
---- ----
$ java -jar myapp.jar someParameter=someValue anotherParameter=anotherValue $ java -jar myapp.jar someParameter=someValue anotherParameter=anotherValue
---- ----
...@@ -43,7 +43,7 @@ To specify batch arguments on the command line, use the regular format (i.e. wit ...@@ -43,7 +43,7 @@ To specify batch arguments on the command line, use the regular format (i.e. wit
If you specify a property of the `Environment` on the command line, it is ignored by the job. If you specify a property of the `Environment` on the command line, it is ignored by the job.
Consider the following command: Consider the following command:
[indent=0,subs="attributes"] [indent=0,subs="verbatim"]
---- ----
$ java -jar myapp.jar --server.port=7070 someParameter=someValue $ java -jar myapp.jar --server.port=7070 someParameter=someValue
---- ----
......
...@@ -13,7 +13,7 @@ When such a file is present, Spring Boot auto-configures a `BuildProperties` bea ...@@ -13,7 +13,7 @@ When such a file is present, Spring Boot auto-configures a `BuildProperties` bea
To generate build information with Maven, add an execution for the `build-info` goal, as shown in the following example: To generate build information with Maven, add an execution for the `build-info` goal, as shown in the following example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim,attributes"]
---- ----
<build> <build>
<plugins> <plugins>
...@@ -37,7 +37,7 @@ TIP: See the {spring-boot-maven-plugin-docs}#goals-build-info[Spring Boot Maven ...@@ -37,7 +37,7 @@ TIP: See the {spring-boot-maven-plugin-docs}#goals-build-info[Spring Boot Maven
The following example does the same with Gradle: The following example does the same with Gradle:
[source,gradle,indent=0,subs="verbatim,attributes"] [source,gradle,indent=0,subs="verbatim"]
---- ----
springBoot { springBoot {
buildInfo() buildInfo()
...@@ -55,7 +55,7 @@ Both Maven and Gradle allow generating a `git.properties` file containing inform ...@@ -55,7 +55,7 @@ Both Maven and Gradle allow generating a `git.properties` file containing inform
For Maven users, the `spring-boot-starter-parent` POM includes a pre-configured plugin to generate a `git.properties` file. For Maven users, the `spring-boot-starter-parent` POM includes a pre-configured plugin to generate a `git.properties` file.
To use it, add the following declaration to your POM: To use it, add the following declaration to your POM:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<build> <build>
<plugins> <plugins>
...@@ -69,7 +69,7 @@ To use it, add the following declaration to your POM: ...@@ -69,7 +69,7 @@ To use it, add the following declaration to your POM:
Gradle users can achieve the same result by using the https://plugins.gradle.org/plugin/com.gorylenko.gradle-git-properties[`gradle-git-properties`] plugin, as shown in the following example: Gradle users can achieve the same result by using the https://plugins.gradle.org/plugin/com.gorylenko.gradle-git-properties[`gradle-git-properties`] plugin, as shown in the following example:
[source,gradle,indent=0] [source,gradle,indent=0,subs="verbatim"]
---- ----
plugins { plugins {
id "com.gorylenko.gradle-git-properties" version "2.2.4" id "com.gorylenko.gradle-git-properties" version "2.2.4"
...@@ -103,7 +103,7 @@ To override dependency versions in Gradle, see {spring-boot-gradle-plugin-docs}# ...@@ -103,7 +103,7 @@ To override dependency versions in Gradle, see {spring-boot-gradle-plugin-docs}#
The `spring-boot-maven-plugin` can be used to create an executable "`fat`" JAR. The `spring-boot-maven-plugin` can be used to create an executable "`fat`" JAR.
If you use the `spring-boot-starter-parent` POM, you can declare the plugin and your jars are repackaged as follows: If you use the `spring-boot-starter-parent` POM, you can declare the plugin and your jars are repackaged as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<build> <build>
<plugins> <plugins>
...@@ -118,7 +118,7 @@ If you use the `spring-boot-starter-parent` POM, you can declare the plugin and ...@@ -118,7 +118,7 @@ If you use the `spring-boot-starter-parent` POM, you can declare the plugin and
If you do not use the parent POM, you can still use the plugin. If you do not use the parent POM, you can still use the plugin.
However, you must additionally add an `<executions>` section, as follows: However, you must additionally add an `<executions>` section, as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<build> <build>
<plugins> <plugins>
...@@ -157,7 +157,7 @@ This classifier is applied to the name of the executable archive, leaving the de ...@@ -157,7 +157,7 @@ This classifier is applied to the name of the executable archive, leaving the de
To configure a classifier of `exec` in Maven, you can use the following configuration: To configure a classifier of `exec` in Maven, you can use the following configuration:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<build> <build>
<plugins> <plugins>
...@@ -187,7 +187,7 @@ WARNING: Care should be taken to ensure that your operating system is configured ...@@ -187,7 +187,7 @@ WARNING: Care should be taken to ensure that your operating system is configured
For example, to indicate that JRuby should be flagged for unpacking by using the Maven Plugin, you would add the following configuration: For example, to indicate that JRuby should be flagged for unpacking by using the Maven Plugin, you would add the following configuration:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<build> <build>
<plugins> <plugins>
...@@ -216,7 +216,7 @@ For example, the `application.yml` configuration file might be excluded from the ...@@ -216,7 +216,7 @@ For example, the `application.yml` configuration file might be excluded from the
In Maven, the executable jar must be the main artifact and you can add a classified jar for the library, as follows: In Maven, the executable jar must be the main artifact and you can add a classified jar for the library, as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<build> <build>
<plugins> <plugins>
...@@ -272,7 +272,7 @@ To make it executable, you can either use the `spring-boot-antlib` module or you ...@@ -272,7 +272,7 @@ To make it executable, you can either use the `spring-boot-antlib` module or you
The following example shows how to build an executable archive with Ant: The following example shows how to build an executable archive with Ant:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<target name="build" depends="compile"> <target name="build" depends="compile">
<jar destfile="target/${ant.project.name}-${spring-boot.version}.jar" compress="false"> <jar destfile="target/${ant.project.name}-${spring-boot.version}.jar" compress="false">
......
...@@ -13,14 +13,14 @@ If you need to externalize some settings, you can bind your `DataSource` to the ...@@ -13,14 +13,14 @@ If you need to externalize some settings, you can bind your `DataSource` to the
The following example shows how to define a data source in a bean: The following example shows how to define a data source in a bean:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/configurecustomdatasource/custom/MyDataSourceConfiguration.java[] include::{docs-java}/howto/dataaccess/configurecustomdatasource/custom/MyDataSourceConfiguration.java[]
---- ----
The following example shows how to define a data source by setting properties: The following example shows how to define a data source by setting properties:
[source,yaml,indent=0,configblocks] [source,yaml,indent=0,subs="verbatim",configblocks]
---- ----
app: app:
datasource: datasource:
...@@ -37,7 +37,7 @@ It also auto-detects the driver based on the JDBC URL. ...@@ -37,7 +37,7 @@ It also auto-detects the driver based on the JDBC URL.
The following example shows how to create a data source by using a `DataSourceBuilder`: The following example shows how to create a data source by using a `DataSourceBuilder`:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/configurecustomdatasource/builder/MyDataSourceConfiguration.java[] include::{docs-java}/howto/dataaccess/configurecustomdatasource/builder/MyDataSourceConfiguration.java[]
---- ----
...@@ -48,7 +48,7 @@ Check the implementation that is going to be used at runtime for more details. ...@@ -48,7 +48,7 @@ Check the implementation that is going to be used at runtime for more details.
The following example shows how to define a JDBC data source by setting properties: The following example shows how to define a JDBC data source by setting properties:
[source,yaml,indent=0,configblocks] [source,yaml,indent=0,subs="verbatim",configblocks]
---- ----
app: app:
datasource: datasource:
...@@ -63,7 +63,7 @@ Because the actual type of the connection pool is not exposed, no keys are gener ...@@ -63,7 +63,7 @@ Because the actual type of the connection pool is not exposed, no keys are gener
Also, if you happen to have Hikari on the classpath, this basic setup does not work, because Hikari has no `url` property (but does have a `jdbcUrl` property). Also, if you happen to have Hikari on the classpath, this basic setup does not work, because Hikari has no `url` property (but does have a `jdbcUrl` property).
In that case, you must rewrite your configuration as follows: In that case, you must rewrite your configuration as follows:
[source,yaml,indent=0,configblocks] [source,yaml,indent=0,subs="verbatim",configblocks]
---- ----
app: app:
datasource: datasource:
...@@ -78,7 +78,7 @@ You cannot change the implementation at runtime, but the list of options will be ...@@ -78,7 +78,7 @@ You cannot change the implementation at runtime, but the list of options will be
The following example shows how create a `HikariDataSource` with `DataSourceBuilder`: The following example shows how create a `HikariDataSource` with `DataSourceBuilder`:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/configurecustomdatasource/simple/MyDataSourceConfiguration.java[] include::{docs-java}/howto/dataaccess/configurecustomdatasource/simple/MyDataSourceConfiguration.java[]
---- ----
...@@ -88,7 +88,7 @@ You can easily initialize a `DataSourceBuilder` from the state of any `DataSourc ...@@ -88,7 +88,7 @@ You can easily initialize a `DataSourceBuilder` from the state of any `DataSourc
However, that would split your configuration into two namespaces: `url`, `username`, `password`, `type`, and `driver` on `spring.datasource` and the rest on your custom namespace (`app.datasource`). However, that would split your configuration into two namespaces: `url`, `username`, `password`, `type`, and `driver` on `spring.datasource` and the rest on your custom namespace (`app.datasource`).
To avoid that, you can redefine a custom `DataSourceProperties` on your custom namespace, as shown in the following example: To avoid that, you can redefine a custom `DataSourceProperties` on your custom namespace, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/configurecustomdatasource/configurable/MyDataSourceConfiguration.java[] include::{docs-java}/howto/dataaccess/configurecustomdatasource/configurable/MyDataSourceConfiguration.java[]
---- ----
...@@ -96,7 +96,7 @@ include::{docs-java}/howto/dataaccess/configurecustomdatasource/configurable/MyD ...@@ -96,7 +96,7 @@ include::{docs-java}/howto/dataaccess/configurecustomdatasource/configurable/MyD
This setup puts you _in sync_ with what Spring Boot does for you by default, except that a dedicated connection pool is chosen (in code) and its settings are exposed in the `app.datasource.configuration` sub namespace. This setup puts you _in sync_ with what Spring Boot does for you by default, except that a dedicated connection pool is chosen (in code) and its settings are exposed in the `app.datasource.configuration` sub namespace.
Because `DataSourceProperties` is taking care of the `url`/`jdbcUrl` translation for you, you can configure it as follows: Because `DataSourceProperties` is taking care of the `url`/`jdbcUrl` translation for you, you can configure it as follows:
[source,yaml,indent=0,configblocks] [source,yaml,indent=0,subs="verbatim",configblocks]
---- ----
app: app:
datasource: datasource:
...@@ -125,7 +125,7 @@ You must, however, mark one of the `DataSource` instances as `@Primary`, because ...@@ -125,7 +125,7 @@ You must, however, mark one of the `DataSource` instances as `@Primary`, because
If you create your own `DataSource`, the auto-configuration backs off. If you create your own `DataSource`, the auto-configuration backs off.
In the following example, we provide the _exact_ same feature set as the auto-configuration provides on the primary data source: In the following example, we provide the _exact_ same feature set as the auto-configuration provides on the primary data source:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/configuretwodatasources/MyDataSourcesConfiguration.java[] include::{docs-java}/howto/dataaccess/configuretwodatasources/MyDataSourcesConfiguration.java[]
---- ----
...@@ -135,7 +135,7 @@ TIP: `firstDataSourceProperties` has to be flagged as `@Primary` so that the dat ...@@ -135,7 +135,7 @@ TIP: `firstDataSourceProperties` has to be flagged as `@Primary` so that the dat
Both data sources are also bound for advanced customizations. Both data sources are also bound for advanced customizations.
For instance, you could configure them as follows: For instance, you could configure them as follows:
[source,yaml,indent=0,configblocks] [source,yaml,indent=0,subs="verbatim",configblocks]
---- ----
app: app:
datasource: datasource:
...@@ -155,7 +155,7 @@ For instance, you could configure them as follows: ...@@ -155,7 +155,7 @@ For instance, you could configure them as follows:
You can apply the same concept to the secondary `DataSource` as well, as shown in the following example: You can apply the same concept to the secondary `DataSource` as well, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/configuretwodatasources/MyCompleteDataSourcesConfiguration.java[] include::{docs-java}/howto/dataaccess/configuretwodatasources/MyCompleteDataSourcesConfiguration.java[]
---- ----
...@@ -186,7 +186,7 @@ For more about Spring Data, see the {spring-data}[Spring Data project page]. ...@@ -186,7 +186,7 @@ For more about Spring Data, see the {spring-data}[Spring Data project page].
Spring Boot tries to guess the location of your `@Entity` definitions, based on the `@EnableAutoConfiguration` it finds. Spring Boot tries to guess the location of your `@Entity` definitions, based on the `@EnableAutoConfiguration` it finds.
To get more control, you can use the `@EntityScan` annotation, as shown in the following example: To get more control, you can use the `@EntityScan` annotation, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/MyApplication.java[] include::{docs-java}/howto/dataaccess/separateentitydefinitionsfromspringconfiguration/MyApplication.java[]
---- ----
...@@ -207,7 +207,7 @@ If you prefer to set the dialect yourself, set the configprop:spring.jpa.databas ...@@ -207,7 +207,7 @@ If you prefer to set the dialect yourself, set the configprop:spring.jpa.databas
The most common options to set are shown in the following example: The most common options to set are shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
jpa: jpa:
...@@ -242,21 +242,21 @@ Alternatively, if `ImplicitNamingStrategy` or `PhysicalNamingStrategy` beans are ...@@ -242,21 +242,21 @@ Alternatively, if `ImplicitNamingStrategy` or `PhysicalNamingStrategy` beans are
By default, Spring Boot configures the physical naming strategy with `SpringPhysicalNamingStrategy`. By default, Spring Boot configures the physical naming strategy with `SpringPhysicalNamingStrategy`.
This implementation provides the same table structure as Hibernate 4: all dots are replaced by underscores and camel casing is replaced by underscores as well. Additionally, by default, all table names are generated in lower case. For example, a `TelephoneNumber` entity is mapped to the `telephone_number` table. If your schema requires mixed-case identifiers, define a custom `SpringPhysicalNamingStrategy` bean, as shown in the following example: This implementation provides the same table structure as Hibernate 4: all dots are replaced by underscores and camel casing is replaced by underscores as well. Additionally, by default, all table names are generated in lower case. For example, a `TelephoneNumber` entity is mapped to the `telephone_number` table. If your schema requires mixed-case identifiers, define a custom `SpringPhysicalNamingStrategy` bean, as shown in the following example:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/configurehibernatenamingstrategy/spring/MyHibernateConfiguration.java[] include::{docs-java}/howto/dataaccess/configurehibernatenamingstrategy/spring/MyHibernateConfiguration.java[]
---- ----
If you prefer to use Hibernate 5's default instead, set the following property: If you prefer to use Hibernate 5's default instead, set the following property:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,properties,subs="verbatim"]
---- ----
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
---- ----
Alternatively, you can configure the following bean: Alternatively, you can configure the following bean:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/configurehibernatenamingstrategy/standard/MyHibernateConfiguration.java[] include::{docs-java}/howto/dataaccess/configurehibernatenamingstrategy/standard/MyHibernateConfiguration.java[]
---- ----
...@@ -273,7 +273,7 @@ Rather than configuring Hibernate to lookup the cache provider again, it is bett ...@@ -273,7 +273,7 @@ Rather than configuring Hibernate to lookup the cache provider again, it is bett
To do this with JCache, first make sure that `org.hibernate:hibernate-jcache` is available on the classpath. To do this with JCache, first make sure that `org.hibernate:hibernate-jcache` is available on the classpath.
Then, add a `HibernatePropertiesCustomizer` bean as shown in the following example: Then, add a `HibernatePropertiesCustomizer` bean as shown in the following example:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/configurehibernatesecondlevelcaching/MyHibernateSecondLevelCacheConfiguration.java[] include::{docs-java}/howto/dataaccess/configurehibernatesecondlevelcaching/MyHibernateSecondLevelCacheConfiguration.java[]
---- ----
...@@ -306,7 +306,7 @@ If you need to use JPA against multiple data sources, you likely need one `Entit ...@@ -306,7 +306,7 @@ If you need to use JPA against multiple data sources, you likely need one `Entit
The `LocalContainerEntityManagerFactoryBean` from Spring ORM allows you to configure an `EntityManagerFactory` for your needs. The `LocalContainerEntityManagerFactoryBean` from Spring ORM allows you to configure an `EntityManagerFactory` for your needs.
You can also reuse `JpaProperties` to bind settings for each `EntityManagerFactory`, as shown in the following example: You can also reuse `JpaProperties` to bind settings for each `EntityManagerFactory`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/MyEntityManagerFactoryConfiguration.java[] include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/MyEntityManagerFactoryConfiguration.java[]
---- ----
...@@ -325,12 +325,12 @@ Alternatively, you might be able to use a JTA transaction manager that spans bot ...@@ -325,12 +325,12 @@ Alternatively, you might be able to use a JTA transaction manager that spans bot
If you use Spring Data, you need to configure `@EnableJpaRepositories` accordingly, as shown in the following examples: If you use Spring Data, you need to configure `@EnableJpaRepositories` accordingly, as shown in the following examples:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/OrderConfiguration.java[] include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/OrderConfiguration.java[]
---- ----
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/CustomerConfiguration.java[] include::{docs-java}/howto/dataaccess/usemultipleentitymanagers/CustomerConfiguration.java[]
---- ----
...@@ -390,7 +390,7 @@ For example, when Flyway is auto-configured, Hibernate is configured to depend u ...@@ -390,7 +390,7 @@ For example, when Flyway is auto-configured, Hibernate is configured to depend u
If you are configuring a component yourself, you can use an `EntityManagerFactoryDependsOnPostProcessor` subclass as a convenient way of setting up the necessary dependencies. If you are configuring a component yourself, you can use an `EntityManagerFactoryDependsOnPostProcessor` subclass as a convenient way of setting up the necessary dependencies.
For example, if you use Hibernate Search with Elasticsearch as its index manager, any `EntityManagerFactory` beans must be configured to depend on the `elasticsearchClient` bean, as shown in the following example: For example, if you use Hibernate Search with Elasticsearch as its index manager, any `EntityManagerFactory` beans must be configured to depend on the `elasticsearchClient` bean, as shown in the following example:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/dataaccess/configureacomponentthatisusedbyjpa/ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java[] include::{docs-java}/howto/dataaccess/configureacomponentthatisusedbyjpa/ElasticsearchEntityManagerFactoryDependsOnPostProcessor.java[]
---- ----
......
...@@ -66,7 +66,7 @@ Spring Boot can detect your database type and execute those scripts on startup. ...@@ -66,7 +66,7 @@ Spring Boot can detect your database type and execute those scripts on startup.
If you use an embedded database, this happens by default. If you use an embedded database, this happens by default.
You can also enable it for any database type, as shown in the following example: You can also enable it for any database type, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
batch: batch:
...@@ -93,7 +93,7 @@ By default, they are in a directory called `classpath:db/migration`, but you can ...@@ -93,7 +93,7 @@ By default, they are in a directory called `classpath:db/migration`, but you can
This is a comma-separated list of one or more `classpath:` or `filesystem:` locations. This is a comma-separated list of one or more `classpath:` or `filesystem:` locations.
For example, the following configuration would search for scripts in both the default classpath location and the `/opt/migration` directory: For example, the following configuration would search for scripts in both the default classpath location and the `/opt/migration` directory:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
flyway: flyway:
...@@ -103,7 +103,7 @@ For example, the following configuration would search for scripts in both the de ...@@ -103,7 +103,7 @@ For example, the following configuration would search for scripts in both the de
You can also add a special `\{vendor}` placeholder to use vendor-specific scripts. You can also add a special `\{vendor}` placeholder to use vendor-specific scripts.
Assume the following: Assume the following:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
flyway: flyway:
...@@ -141,7 +141,7 @@ For example, you can place test-specific migrations in `src/test/resources` and ...@@ -141,7 +141,7 @@ For example, you can place test-specific migrations in `src/test/resources` and
Also, you can use profile-specific configuration to customize `spring.flyway.locations` so that certain migrations run only when a particular profile is active. Also, you can use profile-specific configuration to customize `spring.flyway.locations` so that certain migrations run only when a particular profile is active.
For example, in `application-dev.properties`, you might specify the following setting: For example, in `application-dev.properties`, you might specify the following setting:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
flyway: flyway:
......
...@@ -20,7 +20,7 @@ When Reactor Netty is on the classpath a Reactor Netty-based `WebClient` is auto ...@@ -20,7 +20,7 @@ When Reactor Netty is on the classpath a Reactor Netty-based `WebClient` is auto
To customize the client's handling of network connections, provide a `ClientHttpConnector` bean. To customize the client's handling of network connections, provide a `ClientHttpConnector` bean.
The following example configures a 60 second connect timeout and adds a `ReadTimeoutHandler`: The following example configures a 60 second connect timeout and adds a `ReadTimeoutHandler`:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/httpclients/webclientreactornettycustomization/MyReactorNettyClientConfiguration.java[] include::{docs-java}/howto/httpclients/webclientreactornettycustomization/MyReactorNettyClientConfiguration.java[]
---- ----
......
...@@ -6,7 +6,7 @@ Spring Boot manages both of these dependencies so you can switch to Jedis withou ...@@ -6,7 +6,7 @@ Spring Boot manages both of these dependencies so you can switch to Jedis withou
The following example shows how to do so in Maven: The following example shows how to do so in Maven:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -26,7 +26,7 @@ The following example shows how to do so in Maven: ...@@ -26,7 +26,7 @@ The following example shows how to do so in Maven:
The following example shows how to do so in Gradle: The following example shows how to do so in Gradle:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"] [source,gradle,indent=0,subs="verbatim"]
---- ----
dependencies { dependencies {
implementation('org.springframework.boot:spring-boot-starter-data-redis') { implementation('org.springframework.boot:spring-boot-starter-data-redis') {
......
...@@ -11,7 +11,7 @@ This prevents Jersey from committing the response before Spring Security has had ...@@ -11,7 +11,7 @@ This prevents Jersey from committing the response before Spring Security has had
The `jersey.config.server.response.setStatusOverSendError` property must be set to `true` on the application's `ResourceConfig` bean, as shown in the following example: The `jersey.config.server.response.setStatusOverSendError` property must be set to `true` on the application's `ResourceConfig` bean, as shown in the following example:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/jersey/springsecurity/JerseySetStatusOverSendErrorConfig.java[] include::{docs-java}/howto/jersey/springsecurity/JerseySetStatusOverSendErrorConfig.java[]
---- ----
...@@ -24,7 +24,7 @@ To use Jersey alongside another web framework, such as Spring MVC, it should be ...@@ -24,7 +24,7 @@ To use Jersey alongside another web framework, such as Spring MVC, it should be
First, configure Jersey to use a Filter rather than a Servlet by configuring the configprop:spring.jersey.type[] application property with a value of `filter`. First, configure Jersey to use a Filter rather than a Servlet by configuring the configprop:spring.jersey.type[] application property with a value of `filter`.
Second, configure your `ResourceConfig` to forward requests that would have resulted in a 404, as shown in the following example. Second, configure your `ResourceConfig` to forward requests that would have resulted in a 404, as shown in the following example.
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/jersey/alongsideanotherwebframework/JerseyConfig.java[] include::{docs-java}/howto/jersey/alongsideanotherwebframework/JerseyConfig.java[]
---- ----
...@@ -6,7 +6,7 @@ The recommended way to do that is through the starters, which all depend on `spr ...@@ -6,7 +6,7 @@ The recommended way to do that is through the starters, which all depend on `spr
For a web application, you need only `spring-boot-starter-web`, since it depends transitively on the logging starter. For a web application, you need only `spring-boot-starter-web`, since it depends transitively on the logging starter.
If you use Maven, the following dependency adds logging for you: If you use Maven, the following dependency adds logging for you:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -19,7 +19,7 @@ If Logback is available, it is the first choice. ...@@ -19,7 +19,7 @@ If Logback is available, it is the first choice.
If the only change you need to make to logging is to set the levels of various loggers, you can do so in `application.properties` by using the "logging.level" prefix, as shown in the following example: If the only change you need to make to logging is to set the levels of various loggers, you can do so in `application.properties` by using the "logging.level" prefix, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
logging: logging:
level: level:
...@@ -55,7 +55,7 @@ In addition, a legacy `base.xml` file is provided for compatibility with earlier ...@@ -55,7 +55,7 @@ In addition, a legacy `base.xml` file is provided for compatibility with earlier
A typical custom `logback.xml` file would look something like this: A typical custom `logback.xml` file would look something like this:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
...@@ -91,7 +91,7 @@ Any `logback-spring.groovy` files will not be detected. ...@@ -91,7 +91,7 @@ Any `logback-spring.groovy` files will not be detected.
==== Configure Logback for File-only Output ==== Configure Logback for File-only Output
If you want to disable console logging and write output only to a file, you need a custom `logback-spring.xml` that imports `file-appender.xml` but not `console-appender.xml`, as shown in the following example: If you want to disable console logging and write output only to a file, you need a custom `logback-spring.xml` that imports `file-appender.xml` but not `console-appender.xml`, as shown in the following example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
...@@ -106,7 +106,7 @@ If you want to disable console logging and write output only to a file, you need ...@@ -106,7 +106,7 @@ If you want to disable console logging and write output only to a file, you need
You also need to add `logging.file.name` to your `application.properties` or `application.yaml`, as shown in the following example: You also need to add `logging.file.name` to your `application.properties` or `application.yaml`, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
logging: logging:
file: file:
...@@ -124,7 +124,7 @@ If you do not use the starters, you need to provide (at least) `spring-jcl` in a ...@@ -124,7 +124,7 @@ If you do not use the starters, you need to provide (at least) `spring-jcl` in a
The recommended path is through the starters, even though it requires some jiggling. The recommended path is through the starters, even though it requires some jiggling.
The following example shows how to set up the starters in Maven: The following example shows how to set up the starters in Maven:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -148,7 +148,7 @@ The following example shows how to set up the starters in Maven: ...@@ -148,7 +148,7 @@ The following example shows how to set up the starters in Maven:
And the following example shows one way to set up the starters in Gradle: And the following example shows one way to set up the starters in Gradle:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"] [source,gradle,indent=0,subs="verbatim"]
---- ----
dependencies { dependencies {
compile 'org.springframework.boot:spring-boot-starter-web' compile 'org.springframework.boot:spring-boot-starter-web'
......
...@@ -11,7 +11,7 @@ If your JMS broker does not support transacted sessions, you have to disable the ...@@ -11,7 +11,7 @@ If your JMS broker does not support transacted sessions, you have to disable the
If you create your own `JmsListenerContainerFactory`, there is nothing to do, since, by default it cannot be transacted. If you create your own `JmsListenerContainerFactory`, there is nothing to do, since, by default it cannot be transacted.
If you want to use the `DefaultJmsListenerContainerFactoryConfigurer` to reuse Spring Boot's default, you can disable transacted sessions, as follows: If you want to use the `DefaultJmsListenerContainerFactoryConfigurer` to reuse Spring Boot's default, you can disable transacted sessions, as follows:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.java[] include::{docs-java}/howto/messaging/disabletransactedjmssession/MyJmsConfiguration.java[]
---- ----
......
...@@ -16,7 +16,7 @@ This is possible in both Maven and Gradle. ...@@ -16,7 +16,7 @@ This is possible in both Maven and Gradle.
You can automatically expand properties from the Maven project by using resource filtering. You can automatically expand properties from the Maven project by using resource filtering.
If you use the `spring-boot-starter-parent`, you can then refer to your Maven '`project properties`' with `@..@` placeholders, as shown in the following example: If you use the `spring-boot-starter-parent`, you can then refer to your Maven '`project properties`' with `@..@` placeholders, as shown in the following example:
[source,yaml,indent=0,configblocks] [source,yaml,indent=0,subs="verbatim",configblocks]
---- ----
app: app:
encoding: "@project.build.sourceEncoding@" encoding: "@project.build.sourceEncoding@"
...@@ -33,7 +33,7 @@ See the {spring-boot-maven-plugin-docs}#getting-started[plugin usage page] for m ...@@ -33,7 +33,7 @@ See the {spring-boot-maven-plugin-docs}#getting-started[plugin usage page] for m
If you do not use the starter parent, you need to include the following element inside the `<build/>` element of your `pom.xml`: If you do not use the starter parent, you need to include the following element inside the `<build/>` element of your `pom.xml`:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<resources> <resources>
<resource> <resource>
...@@ -45,7 +45,7 @@ If you do not use the starter parent, you need to include the following element ...@@ -45,7 +45,7 @@ If you do not use the starter parent, you need to include the following element
You also need to include the following element inside `<plugins/>`: You also need to include the following element inside `<plugins/>`:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
...@@ -69,7 +69,7 @@ If that property is not set to `false`, these may be expanded by the build. ...@@ -69,7 +69,7 @@ If that property is not set to `false`, these may be expanded by the build.
==== Automatic Property Expansion Using Gradle ==== Automatic Property Expansion Using Gradle
You can automatically expand properties from the Gradle project by configuring the Java plugin's `processResources` task to do so, as shown in the following example: You can automatically expand properties from the Gradle project by configuring the Java plugin's `processResources` task to do so, as shown in the following example:
[source,gradle,indent=0] [source,gradle,indent=0,subs="verbatim"]
---- ----
processResources { processResources {
expand(project.properties) expand(project.properties)
...@@ -78,7 +78,7 @@ You can automatically expand properties from the Gradle project by configuring t ...@@ -78,7 +78,7 @@ You can automatically expand properties from the Gradle project by configuring t
You can then refer to your Gradle project's properties by using placeholders, as shown in the following example: You can then refer to your Gradle project's properties by using placeholders, as shown in the following example:
[source,yaml,indent=0,configblocks] [source,yaml,indent=0,subs="verbatim",configblocks]
---- ----
app: app:
name: "${name}" name: "${name}"
...@@ -97,7 +97,7 @@ A `SpringApplication` has bean property setters, so you can use its Java API as ...@@ -97,7 +97,7 @@ A `SpringApplication` has bean property setters, so you can use its Java API as
Alternatively, you can externalize the configuration by setting properties in `+spring.main.*+`. Alternatively, you can externalize the configuration by setting properties in `+spring.main.*+`.
For example, in `application.properties`, you might have the following settings: For example, in `application.properties`, you might have the following settings:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
main: main:
...@@ -110,21 +110,21 @@ Then the Spring Boot banner is not printed on startup, and the application is no ...@@ -110,21 +110,21 @@ Then the Spring Boot banner is not printed on startup, and the application is no
Properties defined in external configuration override and replace the values specified with the Java API, with the notable exception of the primary sources. Properties defined in external configuration override and replace the values specified with the Java API, with the notable exception of the primary sources.
Primary sources are those provided to the `SpringApplication` constructor: Primary sources are those provided to the `SpringApplication` constructor:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/propertiesandconfiguration/externalizeconfiguration/application/MyApplication.java[] include::{docs-java}/howto/propertiesandconfiguration/externalizeconfiguration/application/MyApplication.java[]
---- ----
Or to `sources(...)` method of a `SpringApplicationBuilder`: Or to `sources(...)` method of a `SpringApplicationBuilder`:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/propertiesandconfiguration/externalizeconfiguration/builder/MyApplication.java[] include::{docs-java}/howto/propertiesandconfiguration/externalizeconfiguration/builder/MyApplication.java[]
---- ----
Given the examples above, if we have the following configuration: Given the examples above, if we have the following configuration:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
main: main:
...@@ -165,7 +165,7 @@ See {spring-boot-module-code}/context/config/ConfigFileApplicationListener.java[ ...@@ -165,7 +165,7 @@ See {spring-boot-module-code}/context/config/ConfigFileApplicationListener.java[
Some people like to use (for example) `--port=9000` instead of `--server.port=9000` to set configuration properties on the command line. Some people like to use (for example) `--port=9000` instead of `--server.port=9000` to set configuration properties on the command line.
You can enable this behavior by using placeholders in `application.properties`, as shown in the following example: You can enable this behavior by using placeholders in `application.properties`, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
port: "${port:8080}" port: "${port:8080}"
...@@ -183,7 +183,7 @@ In those two platforms, the `PORT` environment variable is set automatically and ...@@ -183,7 +183,7 @@ In those two platforms, the `PORT` environment variable is set automatically and
=== Use YAML for External Properties === Use YAML for External Properties
YAML is a superset of JSON and, as such, is a convenient syntax for storing external properties in a hierarchical format, as shown in the following example: YAML is a superset of JSON and, as such, is a convenient syntax for storing external properties in a hierarchical format, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes"] [source,yaml,indent=0,subs="verbatim"]
---- ----
spring: spring:
application: application:
...@@ -201,7 +201,7 @@ A YAML file is parsed to a Java `Map<String,Object>` (like a JSON object), and S ...@@ -201,7 +201,7 @@ A YAML file is parsed to a Java `Map<String,Object>` (like a JSON object), and S
The preceding example YAML corresponds to the following `application.properties` file: The preceding example YAML corresponds to the following `application.properties` file:
[source,properties,indent=0,subs="verbatim,quotes,attributes",configprops] [source,properties,indent=0,subs="verbatim",configprops]
---- ----
spring.application.name=cruncher spring.application.name=cruncher
spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.driver-class-name=com.mysql.jdbc.Driver
...@@ -218,14 +218,14 @@ See "`<<features#features.external-config.yaml>>`" in the '`Spring Boot features ...@@ -218,14 +218,14 @@ See "`<<features#features.external-config.yaml>>`" in the '`Spring Boot features
The Spring `Environment` has an API for this, but you would normally set a System property (configprop:spring.profiles.active[]) or an OS environment variable (configprop:spring.profiles.active[format=envvar]). The Spring `Environment` has an API for this, but you would normally set a System property (configprop:spring.profiles.active[]) or an OS environment variable (configprop:spring.profiles.active[format=envvar]).
Also, you can launch your application with a `-D` argument (remember to put it before the main class or jar archive), as follows: Also, you can launch your application with a `-D` argument (remember to put it before the main class or jar archive), as follows:
[indent=0,subs="verbatim,quotes,attributes"] [indent=0,subs="verbatim"]
---- ----
$ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar $ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar
---- ----
In Spring Boot, you can also set the active profile in `application.properties`, as shown in the following example: In Spring Boot, you can also set the active profile in `application.properties`, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
profiles: profiles:
...@@ -246,7 +246,7 @@ Spring Boot supports multi-document YAML and Properties files (see <<features#fe ...@@ -246,7 +246,7 @@ Spring Boot supports multi-document YAML and Properties files (see <<features#fe
If a document contains a `spring.config.activate.on-profile` key, then the profiles value (a comma-separated list of profiles or a profile expression) is fed into the Spring `Environment.acceptsProfiles()` method. If a document contains a `spring.config.activate.on-profile` key, then the profiles value (a comma-separated list of profiles or a profile expression) is fed into the Spring `Environment.acceptsProfiles()` method.
If the profile expression matches then that document is included in the final merge (otherwise, it is not), as shown in the following example: If the profile expression matches then that document is included in the final merge (otherwise, it is not), as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim,attributes",configprops,configblocks]
---- ----
server: server:
port: 9000 port: 9000
......
...@@ -28,7 +28,7 @@ If you use Tomcat as a servlet container, then Spring Boot adds Tomcat's own `Re ...@@ -28,7 +28,7 @@ If you use Tomcat as a servlet container, then Spring Boot adds Tomcat's own `Re
The standard behavior is determined by the presence or absence of certain request headers (`x-forwarded-for` and `x-forwarded-proto`), whose names are conventional, so it should work with most front-end proxies. The standard behavior is determined by the presence or absence of certain request headers (`x-forwarded-for` and `x-forwarded-proto`), whose names are conventional, so it should work with most front-end proxies.
You can switch on the valve by adding some entries to `application.properties`, as shown in the following example: You can switch on the valve by adding some entries to `application.properties`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
tomcat: tomcat:
...@@ -42,7 +42,7 @@ Alternatively, you can add the `RemoteIpValve` by customizing the `TomcatServlet ...@@ -42,7 +42,7 @@ Alternatively, you can add the `RemoteIpValve` by customizing the `TomcatServlet
To configure Spring Security to require a secure channel for all (or some) requests, consider adding your own `SecurityFilterChain` bean that adds the following `HttpSecurity` configuration: To configure Spring Security to require a secure channel for all (or some) requests, consider adding your own `SecurityFilterChain` bean that adds the following `HttpSecurity` configuration:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/security/enablehttps/MySecurityConfig.java[] include::{docs-java}/howto/security/enablehttps/MySecurityConfig.java[]
---- ----
...@@ -10,7 +10,7 @@ This section answers common questions about Spring MVC and Spring Boot. ...@@ -10,7 +10,7 @@ This section answers common questions about Spring MVC and Spring Boot.
=== Write a JSON REST Service === Write a JSON REST Service
Any Spring `@RestController` in a Spring Boot application should render JSON response by default as long as Jackson2 is on the classpath, as shown in the following example: Any Spring `@RestController` in a Spring Boot application should render JSON response by default as long as Jackson2 is on the classpath, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/springmvc/writejsonrestservice/MyController.java[] include::{docs-java}/howto/springmvc/writejsonrestservice/MyController.java[]
---- ----
...@@ -26,7 +26,7 @@ If you have the Jackson XML extension (`jackson-dataformat-xml`) on the classpat ...@@ -26,7 +26,7 @@ If you have the Jackson XML extension (`jackson-dataformat-xml`) on the classpat
The previous example that we used for JSON would work. The previous example that we used for JSON would work.
To use the Jackson XML renderer, add the following dependency to your project: To use the Jackson XML renderer, add the following dependency to your project:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependency> <dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId> <groupId>com.fasterxml.jackson.dataformat</groupId>
...@@ -36,7 +36,7 @@ To use the Jackson XML renderer, add the following dependency to your project: ...@@ -36,7 +36,7 @@ To use the Jackson XML renderer, add the following dependency to your project:
If Jackson's XML extension is not available and JAXB is available, XML can be rendered with the additional requirement of having `MyThing` annotated as `@XmlRootElement`, as shown in the following example: If Jackson's XML extension is not available and JAXB is available, XML can be rendered with the additional requirement of having `MyThing` annotated as `@XmlRootElement`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/springmvc/writexmlrestservice/MyThing.java[] include::{docs-java}/howto/springmvc/writexmlrestservice/MyThing.java[]
---- ----
...@@ -44,7 +44,7 @@ include::{docs-java}/howto/springmvc/writexmlrestservice/MyThing.java[] ...@@ -44,7 +44,7 @@ include::{docs-java}/howto/springmvc/writexmlrestservice/MyThing.java[]
JAXB is only available out of the box with Java 8. JAXB is only available out of the box with Java 8.
If you're using a more recent Java generation, add the following dependency to your project: If you're using a more recent Java generation, add the following dependency to your project:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependency> <dependency>
<groupId>org.glassfish.jaxb</groupId> <groupId>org.glassfish.jaxb</groupId>
......
...@@ -5,7 +5,7 @@ It integrates with JUnit, allowing you to write a test class that can start up a ...@@ -5,7 +5,7 @@ It integrates with JUnit, allowing you to write a test class that can start up a
Testcontainers is especially useful for writing integration tests that talk to a real backend service such as MySQL, MongoDB, Cassandra etc. Testcontainers is especially useful for writing integration tests that talk to a real backend service such as MySQL, MongoDB, Cassandra etc.
Testcontainers can be used in a Spring Boot test as follows: Testcontainers can be used in a Spring Boot test as follows:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/testcontainers/vanilla/MyIntegrationTests.java include::{docs-java}/howto/testcontainers/vanilla/MyIntegrationTests.java
---- ----
...@@ -15,7 +15,7 @@ In most cases, you will need to configure the application using details from the ...@@ -15,7 +15,7 @@ In most cases, you will need to configure the application using details from the
This can be done with a static `@DynamicPropertySource` method that allows adding dynamic property values to the Spring Environment. This can be done with a static `@DynamicPropertySource` method that allows adding dynamic property values to the Spring Environment.
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/testcontainers/dynamicproperties/MyIntegrationTests.java include::{docs-java}/howto/testcontainers/dynamicproperties/MyIntegrationTests.java
---- ----
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Spring Security provides support for running tests as a specific user. Spring Security provides support for running tests as a specific user.
For example, the test in the snippet below will run with an authenticated user that has the `ADMIN` role. For example, the test in the snippet below will run with an authenticated user that has the `ADMIN` role.
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/testingwithspringsecurity/MySecurityTests.java[] include::{docs-java}/howto/testingwithspringsecurity/MySecurityTests.java[]
---- ----
......
...@@ -14,7 +14,7 @@ The first step in producing a deployable war file is to provide a `SpringBootSer ...@@ -14,7 +14,7 @@ The first step in producing a deployable war file is to provide a `SpringBootSer
Doing so makes use of Spring Framework's Servlet 3.0 support and lets you configure your application when it is launched by the servlet container. Doing so makes use of Spring Framework's Servlet 3.0 support and lets you configure your application when it is launched by the servlet container.
Typically, you should update your application's main class to extend `SpringBootServletInitializer`, as shown in the following example: Typically, you should update your application's main class to extend `SpringBootServletInitializer`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/traditionaldeployment/war/MyApplication.java[] include::{docs-java}/howto/traditionaldeployment/war/MyApplication.java[]
---- ----
...@@ -22,14 +22,14 @@ include::{docs-java}/howto/traditionaldeployment/war/MyApplication.java[] ...@@ -22,14 +22,14 @@ include::{docs-java}/howto/traditionaldeployment/war/MyApplication.java[]
The next step is to update your build configuration such that your project produces a war file rather than a jar file. The next step is to update your build configuration such that your project produces a war file rather than a jar file.
If you use Maven and `spring-boot-starter-parent` (which configures Maven's war plugin for you), all you need to do is to modify `pom.xml` to change the packaging to war, as follows: If you use Maven and `spring-boot-starter-parent` (which configures Maven's war plugin for you), all you need to do is to modify `pom.xml` to change the packaging to war, as follows:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<packaging>war</packaging> <packaging>war</packaging>
---- ----
If you use Gradle, you need to modify `build.gradle` to apply the war plugin to the project, as follows: If you use Gradle, you need to modify `build.gradle` to apply the war plugin to the project, as follows:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"] [source,gradle,indent=0,subs="verbatim"]
---- ----
apply plugin: 'war' apply plugin: 'war'
---- ----
...@@ -39,7 +39,7 @@ To do so, you need to mark the embedded servlet container dependency as being pr ...@@ -39,7 +39,7 @@ To do so, you need to mark the embedded servlet container dependency as being pr
If you use Maven, the following example marks the servlet container (Tomcat, in this case) as being provided: If you use Maven, the following example marks the servlet container (Tomcat, in this case) as being provided:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependencies> <dependencies>
<!-- … --> <!-- … -->
...@@ -54,7 +54,7 @@ If you use Maven, the following example marks the servlet container (Tomcat, in ...@@ -54,7 +54,7 @@ If you use Maven, the following example marks the servlet container (Tomcat, in
If you use Gradle, the following example marks the servlet container (Tomcat, in this case) as being provided: If you use Gradle, the following example marks the servlet container (Tomcat, in this case) as being provided:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"] [source,gradle,indent=0,subs="verbatim"]
---- ----
dependencies { dependencies {
// … // …
...@@ -79,7 +79,7 @@ See the https://spring.io/guides/gs/convert-jar-to-war/[Getting Started Guide on ...@@ -79,7 +79,7 @@ See the https://spring.io/guides/gs/convert-jar-to-war/[Getting Started Guide on
To create a deployable war by extending `SpringBootServletInitializer` (for example, in a class called `Application`) and adding the Spring Boot `@SpringBootApplication` annotation, use code similar to that shown in the following example: To create a deployable war by extending `SpringBootServletInitializer` (for example, in a class called `Application`) and adding the Spring Boot `@SpringBootApplication` annotation, use code similar to that shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/MyApplication.java[tag=!main] include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/MyApplication.java[tag=!main]
---- ----
...@@ -101,7 +101,7 @@ If you have other features in your application (for instance, using other servle ...@@ -101,7 +101,7 @@ If you have other features in your application (for instance, using other servle
Once the war file is working, you can make it executable by adding a `main` method to your `Application`, as shown in the following example: Once the war file is working, you can make it executable by adding a `main` method to your `Application`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/MyApplication.java[tag=main] include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/MyApplication.java[tag=main]
---- ----
...@@ -110,7 +110,7 @@ include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/MyAp ...@@ -110,7 +110,7 @@ include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/MyAp
==== ====
If you intend to start your application as a war or as an executable application, you need to share the customizations of the builder in a method that is both available to the `SpringBootServletInitializer` callback and in the `main` method in a class similar to the following: If you intend to start your application as a war or as an executable application, you need to share the customizations of the builder in a method that is both available to the `SpringBootServletInitializer` callback and in the `main` method in a class similar to the following:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/both/MyApplication.java[] include::{docs-java}/howto/traditionaldeployment/convertexistingapplication/both/MyApplication.java[]
---- ----
...@@ -144,7 +144,7 @@ To deploy a Spring Boot application to WebLogic, you must ensure that your servl ...@@ -144,7 +144,7 @@ To deploy a Spring Boot application to WebLogic, you must ensure that your servl
A typical initializer for WebLogic should resemble the following example: A typical initializer for WebLogic should resemble the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/traditionaldeployment/weblogic/MyApplication.java[] include::{docs-java}/howto/traditionaldeployment/weblogic/MyApplication.java[]
---- ----
...@@ -152,7 +152,7 @@ include::{docs-java}/howto/traditionaldeployment/weblogic/MyApplication.java[] ...@@ -152,7 +152,7 @@ include::{docs-java}/howto/traditionaldeployment/weblogic/MyApplication.java[]
If you use Logback, you also need to tell WebLogic to prefer the packaged version rather than the version that was pre-installed with the server. If you use Logback, you also need to tell WebLogic to prefer the packaged version rather than the version that was pre-installed with the server.
You can do so by adding a `WEB-INF/weblogic.xml` file with the following contents: You can do so by adding a `WEB-INF/weblogic.xml` file with the following contents:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app <wls:weblogic-web-app
......
...@@ -18,7 +18,7 @@ To help with this process, Spring Boot provides a separate starter for each of t ...@@ -18,7 +18,7 @@ To help with this process, Spring Boot provides a separate starter for each of t
The following Maven example shows how to exclude Tomcat and include Jetty for Spring MVC: The following Maven example shows how to exclude Tomcat and include Jetty for Spring MVC:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<properties> <properties>
<servlet-api.version>3.1.0</servlet-api.version> <servlet-api.version>3.1.0</servlet-api.version>
...@@ -46,7 +46,7 @@ If you wish to use Jetty 10, which does support Servlet 4.0, override the `jetty ...@@ -46,7 +46,7 @@ If you wish to use Jetty 10, which does support Servlet 4.0, override the `jetty
The following Gradle example shows how to use Undertow in place of Reactor Netty for Spring WebFlux: The following Gradle example shows how to use Undertow in place of Reactor Netty for Spring WebFlux:
[source,gradle,indent=0,subs="verbatim,quotes,attributes"] [source,gradle,indent=0,subs="verbatim"]
---- ----
configurations.all { configurations.all {
resolutionStrategy.dependencySubstitution.all { dependency -> resolutionStrategy.dependencySubstitution.all { dependency ->
...@@ -71,7 +71,7 @@ NOTE: `spring-boot-starter-reactor-netty` is required to use the `WebClient` cla ...@@ -71,7 +71,7 @@ NOTE: `spring-boot-starter-reactor-netty` is required to use the `WebClient` cla
If your classpath contains the necessary bits to start a web server, Spring Boot will automatically start it. If your classpath contains the necessary bits to start a web server, Spring Boot will automatically start it.
To disable this behavior configure the `WebApplicationType` in your `application.properties`, as shown in the following example: To disable this behavior configure the `WebApplicationType` in your `application.properties`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
main: main:
...@@ -104,7 +104,7 @@ The best way to get that and be sure it has been initialized is to add a `@Bean` ...@@ -104,7 +104,7 @@ The best way to get that and be sure it has been initialized is to add a `@Bean`
Tests that use `@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)` can also inject the actual port into a field by using the `@LocalServerPort` annotation, as shown in the following example: Tests that use `@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)` can also inject the actual port into a field by using the `@LocalServerPort` annotation, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/webserver/discoverport/MyWebIntegrationTests.java[] include::{docs-java}/howto/webserver/discoverport/MyWebIntegrationTests.java[]
---- ----
...@@ -124,7 +124,7 @@ Contrary to a test, application code callbacks are processed early (before the v ...@@ -124,7 +124,7 @@ Contrary to a test, application code callbacks are processed early (before the v
HTTP response compression is supported by Jetty, Tomcat, and Undertow. HTTP response compression is supported by Jetty, Tomcat, and Undertow.
It can be enabled in `application.properties`, as follows: It can be enabled in `application.properties`, as follows:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
compression: compression:
...@@ -154,7 +154,7 @@ You can configure this behavior by setting the configprop:server.compression.mim ...@@ -154,7 +154,7 @@ You can configure this behavior by setting the configprop:server.compression.mim
SSL can be configured declaratively by setting the various `+server.ssl.*+` properties, typically in `application.properties` or `application.yml`. SSL can be configured declaratively by setting the various `+server.ssl.*+` properties, typically in `application.properties` or `application.yml`.
The following example shows setting SSL properties in `application.properties`: The following example shows setting SSL properties in `application.properties`:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
port: 8443 port: 8443
...@@ -194,7 +194,7 @@ More on this in the https://tomcat.apache.org/tomcat-9.0-doc/apr.html[official T ...@@ -194,7 +194,7 @@ More on this in the https://tomcat.apache.org/tomcat-9.0-doc/apr.html[official T
Starting Tomcat 9.0.x on JDK 8 with HTTP/2 and SSL enabled but without that native support logs the following error: Starting Tomcat 9.0.x on JDK 8 with HTTP/2 and SSL enabled but without that native support logs the following error:
[indent=0,subs="attributes"] [indent=0,subs="verbatim"]
---- ----
ERROR 8787 --- [ main] o.a.coyote.http11.Http11NioProtocol : The upgrade handler [org.apache.coyote.http2.Http2Protocol] for [h2] only supports upgrade via ALPN but has been configured for the ["https-jsse-nio-8443"] connector that does not support ALPN. ERROR 8787 --- [ main] o.a.coyote.http11.Http11NioProtocol : The upgrade handler [org.apache.coyote.http2.Http2Protocol] for [h2] only supports upgrade via ALPN but has been configured for the ["https-jsse-nio-8443"] connector that does not support ALPN.
---- ----
...@@ -246,7 +246,7 @@ You can declare such a component and get access to the server factory relevant t ...@@ -246,7 +246,7 @@ You can declare such a component and get access to the server factory relevant t
The example below is for Tomcat with the `spring-boot-starter-web` (Servlet stack): The example below is for Tomcat with the `spring-boot-starter-web` (Servlet stack):
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/webserver/configure/MyTomcatWebServerCustomizer.java[] include::{docs-java}/howto/webserver/configure/MyTomcatWebServerCustomizer.java[]
---- ----
...@@ -319,7 +319,7 @@ Like any other Spring bean, you can define the order of Servlet filter beans; pl ...@@ -319,7 +319,7 @@ Like any other Spring bean, you can define the order of Servlet filter beans; pl
As <<howto#howto.webserver.add-servlet-filter-listener.spring-bean,described earlier>>, any `Servlet` or `Filter` beans are registered with the servlet container automatically. As <<howto#howto.webserver.add-servlet-filter-listener.spring-bean,described earlier>>, any `Servlet` or `Filter` beans are registered with the servlet container automatically.
To disable registration of a particular `Filter` or `Servlet` bean, create a registration bean for it and mark it as disabled, as shown in the following example: To disable registration of a particular `Filter` or `Servlet` bean, create a registration bean for it and mark it as disabled, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/webserver/addservletfilterlistener/springbean/disable/MyFilterConfiguration.java[] include::{docs-java}/howto/webserver/addservletfilterlistener/springbean/disable/MyFilterConfiguration.java[]
---- ----
...@@ -339,7 +339,7 @@ Access logs can be configured for Tomcat, Undertow, and Jetty through their resp ...@@ -339,7 +339,7 @@ Access logs can be configured for Tomcat, Undertow, and Jetty through their resp
For instance, the following settings log access on Tomcat with a {tomcat-docs}/config/valve.html#Access_Logging[custom pattern]. For instance, the following settings log access on Tomcat with a {tomcat-docs}/config/valve.html#Access_Logging[custom pattern].
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
tomcat: tomcat:
...@@ -355,7 +355,7 @@ In the preceding example, the logs are available in `my-tomcat/logs` relative to ...@@ -355,7 +355,7 @@ In the preceding example, the logs are available in `my-tomcat/logs` relative to
Access logging for Undertow can be configured in a similar fashion, as shown in the following example: Access logging for Undertow can be configured in a similar fashion, as shown in the following example:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
undertow: undertow:
...@@ -369,7 +369,7 @@ You can customize this location by setting the configprop:server.undertow.access ...@@ -369,7 +369,7 @@ You can customize this location by setting the configprop:server.undertow.access
Finally, access logging for Jetty can also be configured as follows: Finally, access logging for Jetty can also be configured as follows:
[source,yaml,indent=0,subs="verbatim,quotes,attributes",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
jetty: jetty:
...@@ -410,7 +410,7 @@ In all other instances, it defaults to `NONE`. ...@@ -410,7 +410,7 @@ In all other instances, it defaults to `NONE`.
==== Customize Tomcat's Proxy Configuration ==== Customize Tomcat's Proxy Configuration
If you use Tomcat, you can additionally configure the names of the headers used to carry "`forwarded`" information, as shown in the following example: If you use Tomcat, you can additionally configure the names of the headers used to carry "`forwarded`" information, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
tomcat: tomcat:
...@@ -423,7 +423,7 @@ Tomcat is also configured with a default regular expression that matches interna ...@@ -423,7 +423,7 @@ Tomcat is also configured with a default regular expression that matches interna
By default, IP addresses in `10/8`, `192.168/16`, `169.254/16` and `127/8` are trusted. By default, IP addresses in `10/8`, `192.168/16`, `169.254/16` and `127/8` are trusted.
You can customize the valve's configuration by adding an entry to `application.properties`, as shown in the following example: You can customize the valve's configuration by adding an entry to `application.properties`, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
tomcat: tomcat:
...@@ -441,7 +441,7 @@ You can take complete control of the configuration of Tomcat's `RemoteIpValve` b ...@@ -441,7 +441,7 @@ You can take complete control of the configuration of Tomcat's `RemoteIpValve` b
=== Enable Multiple Connectors with Tomcat === Enable Multiple Connectors with Tomcat
You can add an `org.apache.catalina.connector.Connector` to the `TomcatServletWebServerFactory`, which can allow multiple connectors, including HTTP and HTTPS connectors, as shown in the following example: You can add an `org.apache.catalina.connector.Connector` to the `TomcatServletWebServerFactory`, which can allow multiple connectors, including HTTP and HTTPS connectors, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.java[] include::{docs-java}/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.java[]
---- ----
...@@ -461,7 +461,7 @@ If at all possible, you should consider updating your code to only store values ...@@ -461,7 +461,7 @@ If at all possible, you should consider updating your code to only store values
If, however, you cannot change the way that cookies are written, you can instead configure Tomcat to use a `LegacyCookieProcessor`. If, however, you cannot change the way that cookies are written, you can instead configure Tomcat to use a `LegacyCookieProcessor`.
To switch to the `LegacyCookieProcessor`, use an `WebServerFactoryCustomizer` bean that adds a `TomcatContextCustomizer`, as shown in the following example: To switch to the `LegacyCookieProcessor`, use an `WebServerFactoryCustomizer` bean that adds a `TomcatContextCustomizer`, as shown in the following example:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/webserver/usetomcatlegacycookieprocessor/MyLegacyCookieProcessorConfiguration.java[] include::{docs-java}/howto/webserver/usetomcatlegacycookieprocessor/MyLegacyCookieProcessorConfiguration.java[]
---- ----
...@@ -474,7 +474,7 @@ Embedded Tomcat's MBean registry is disabled by default. ...@@ -474,7 +474,7 @@ Embedded Tomcat's MBean registry is disabled by default.
This minimizes Tomcat's memory footprint. This minimizes Tomcat's memory footprint.
If you want to use Tomcat's MBeans, for example so that they can be used to expose metrics via Micrometer, you must use the configprop:server.tomcat.mbeanregistry.enabled[] property to do so, as shown in the following example: If you want to use Tomcat's MBeans, for example so that they can be used to expose metrics via Micrometer, you must use the configprop:server.tomcat.mbeanregistry.enabled[] property to do so, as shown in the following example:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
server: server:
tomcat: tomcat:
...@@ -488,7 +488,7 @@ server: ...@@ -488,7 +488,7 @@ server:
=== Enable Multiple Listeners with Undertow === Enable Multiple Listeners with Undertow
Add an `UndertowBuilderCustomizer` to the `UndertowServletWebServerFactory` and add a listener to the `Builder`, as shown in the following example: Add an `UndertowBuilderCustomizer` to the `UndertowServletWebServerFactory` and add a listener to the `Builder`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/webserver/enablemultiplelistenersinundertow/MyUndertowConfiguration.java[] include::{docs-java}/howto/webserver/enablemultiplelistenersinundertow/MyUndertowConfiguration.java[]
---- ----
...@@ -499,7 +499,7 @@ include::{docs-java}/howto/webserver/enablemultiplelistenersinundertow/MyUnderto ...@@ -499,7 +499,7 @@ include::{docs-java}/howto/webserver/enablemultiplelistenersinundertow/MyUnderto
=== Create WebSocket Endpoints Using @ServerEndpoint === Create WebSocket Endpoints Using @ServerEndpoint
If you want to use `@ServerEndpoint` in a Spring Boot application that used an embedded container, you must declare a single `ServerEndpointExporter` `@Bean`, as shown in the following example: If you want to use `@ServerEndpoint` in a Spring Boot application that used an embedded container, you must declare a single `ServerEndpointExporter` `@Bean`, as shown in the following example:
[source,java,indent=0,subs="verbatim,quotes,attributes"] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/howto/webserver/createwebsocketendpointsusingserverendpoint/MyWebSocketConfiguration.java[] include::{docs-java}/howto/webserver/createwebsocketendpointsusingserverendpoint/MyWebSocketConfiguration.java[]
---- ----
......
...@@ -25,7 +25,7 @@ Doing so enables debug logs for a selection of core loggers and logs a condition ...@@ -25,7 +25,7 @@ Doing so enables debug logs for a selection of core loggers and logs a condition
=== Disabling Specific Auto-configuration Classes === Disabling Specific Auto-configuration Classes
If you find that specific auto-configuration classes that you do not want are being applied, you can use the exclude attribute of `@SpringBootApplication` to disable them, as shown in the following example: If you find that specific auto-configuration classes that you do not want are being applied, you can use the exclude attribute of `@SpringBootApplication` to disable them, as shown in the following example:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/using/autoconfiguration/disablingspecific/MyApplication.java[] include::{docs-java}/using/autoconfiguration/disablingspecific/MyApplication.java[]
---- ----
......
...@@ -47,7 +47,7 @@ The `spring-boot-antlib` "`AntLib`" module is also available to help Ant create ...@@ -47,7 +47,7 @@ The `spring-boot-antlib` "`AntLib`" module is also available to help Ant create
To declare dependencies, a typical `ivy.xml` file looks something like the following example: To declare dependencies, a typical `ivy.xml` file looks something like the following example:
[source,xml,indent=0] [source,xml,indent=0,subs="verbatim"]
---- ----
<ivy-module version="2.0"> <ivy-module version="2.0">
<info organisation="org.springframework.boot" module="spring-boot-sample-ant" /> <info organisation="org.springframework.boot" module="spring-boot-sample-ant" />
...@@ -64,7 +64,7 @@ To declare dependencies, a typical `ivy.xml` file looks something like the follo ...@@ -64,7 +64,7 @@ To declare dependencies, a typical `ivy.xml` file looks something like the follo
A typical `build.xml` looks like the following example: A typical `build.xml` looks like the following example:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim,attributes"]
---- ----
<project <project
xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:ivy="antlib:org.apache.ivy.ant"
......
...@@ -5,7 +5,7 @@ The `spring-boot-devtools` module can be included in any project to provide addi ...@@ -5,7 +5,7 @@ The `spring-boot-devtools` module can be included in any project to provide addi
To include devtools support, add the module dependency to your build, as shown in the following listings for Maven and Gradle: To include devtools support, add the module dependency to your build, as shown in the following listings for Maven and Gradle:
.Maven .Maven
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<dependencies> <dependencies>
<dependency> <dependency>
...@@ -17,7 +17,7 @@ To include devtools support, add the module dependency to your build, as shown i ...@@ -17,7 +17,7 @@ To include devtools support, add the module dependency to your build, as shown i
---- ----
.Gradle .Gradle
[source,gradle,indent=0,subs="attributes"] [source,gradle,indent=0,subs="verbatim"]
---- ----
dependencies { dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools") developmentOnly("org.springframework.boot:spring-boot-devtools")
...@@ -117,7 +117,7 @@ The report shows the changes to your application's auto-configuration as you mak ...@@ -117,7 +117,7 @@ The report shows the changes to your application's auto-configuration as you mak
To disable the logging of the report, set the following property: To disable the logging of the report, set the following property:
[source,yaml,indent=0,configblocks] [source,yaml,indent=0,subs="verbatim",configblocks]
---- ----
spring: spring:
devtools: devtools:
...@@ -135,7 +135,7 @@ By default, changing resources in `/META-INF/maven`, `/META-INF/resources`, `/re ...@@ -135,7 +135,7 @@ By default, changing resources in `/META-INF/maven`, `/META-INF/resources`, `/re
If you want to customize these exclusions, you can use the configprop:spring.devtools.restart.exclude[] property. If you want to customize these exclusions, you can use the configprop:spring.devtools.restart.exclude[] property.
For example, to exclude only `/static` and `/public` you would set the following property: For example, to exclude only `/static` and `/public` you would set the following property:
[source,yaml,indent=0,configblocks] [source,yaml,indent=0,subs="verbatim",configblocks]
---- ----
spring: spring:
devtools: devtools:
...@@ -162,7 +162,7 @@ In most cases, you can set this property in your `application.properties` (doing ...@@ -162,7 +162,7 @@ In most cases, you can set this property in your `application.properties` (doing
If you need to _completely_ disable restart support (for example, because it does not work with a specific library), you need to set the configprop:spring.devtools.restart.enabled[] `System` property to `false` before calling `SpringApplication.run(...)`, as shown in the following example: If you need to _completely_ disable restart support (for example, because it does not work with a specific library), you need to set the configprop:spring.devtools.restart.enabled[] `System` property to `false` before calling `SpringApplication.run(...)`, as shown in the following example:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/devtools/restart/disable/MyApplication.java[] include::{docs-java}/devtools/restart/disable/MyApplication.java[]
---- ----
...@@ -191,7 +191,7 @@ For example, if you have a project with the following structure: ...@@ -191,7 +191,7 @@ For example, if you have a project with the following structure:
Then your `trigger-file` property would be: Then your `trigger-file` property would be:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
devtools: devtools:
...@@ -224,7 +224,7 @@ The `spring-devtools.properties` file can contain properties prefixed with `rest ...@@ -224,7 +224,7 @@ The `spring-devtools.properties` file can contain properties prefixed with `rest
The `include` elements are items that should be pulled up into the "`restart`" classloader, and the `exclude` elements are items that should be pushed down into the "`base`" classloader. The `include` elements are items that should be pulled up into the "`restart`" classloader, and the `exclude` elements are items that should be pushed down into the "`base`" classloader.
The value of the property is a regex pattern that is applied to the classpath, as shown in the following example: The value of the property is a regex pattern that is applied to the classpath, as shown in the following example:
[source,yaml,indent=0,configblocks] [source,yaml,indent=0,subs="verbatim",configblocks]
---- ----
restart: restart:
exclude: exclude:
...@@ -277,7 +277,7 @@ You can configure global devtools settings by adding any of the following files ...@@ -277,7 +277,7 @@ You can configure global devtools settings by adding any of the following files
Any properties added to these file apply to _all_ Spring Boot applications on your machine that use devtools. Any properties added to these file apply to _all_ Spring Boot applications on your machine that use devtools.
For example, to configure restart to always use a <<using#using.devtools.restart.triggerfile, trigger file>>, you would add the following property to your `spring-boot-devtools` file: For example, to configure restart to always use a <<using#using.devtools.restart.triggerfile, trigger file>>, you would add the following property to your `spring-boot-devtools` file:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
devtools: devtools:
...@@ -304,7 +304,7 @@ Profile specific filenames (of the form `spring-boot-devtools-<profile>.properti ...@@ -304,7 +304,7 @@ Profile specific filenames (of the form `spring-boot-devtools-<profile>.properti
Since Spring Boot relies entirely on the IDE to compile and copy files into the location from where Spring Boot can read them, you might find that there are times when certain changes are not reflected when devtools restarts the application. Since Spring Boot relies entirely on the IDE to compile and copy files into the location from where Spring Boot can read them, you might find that there are times when certain changes are not reflected when devtools restarts the application.
If you observe such problems constantly, try increasing the `spring.devtools.restart.poll-interval` and `spring.devtools.restart.quiet-period` parameters to the values that fit your development environment: If you observe such problems constantly, try increasing the `spring.devtools.restart.poll-interval` and `spring.devtools.restart.quiet-period` parameters to the values that fit your development environment:
[source,yaml,indent=0,configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
devtools: devtools:
...@@ -328,7 +328,7 @@ You should never enable support on a production deployment. ...@@ -328,7 +328,7 @@ You should never enable support on a production deployment.
To enable it, you need to make sure that `devtools` is included in the repackaged archive, as shown in the following listing: To enable it, you need to make sure that `devtools` is included in the repackaged archive, as shown in the following listing:
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim"]
---- ----
<build> <build>
<plugins> <plugins>
...@@ -368,7 +368,7 @@ For example, if you are using Eclipse or STS and you have a project named `my-ap ...@@ -368,7 +368,7 @@ For example, if you are using Eclipse or STS and you have a project named `my-ap
A running remote client might resemble the following listing: A running remote client might resemble the following listing:
[indent=0,subs="attributes"] [indent=0,subs="verbatim"]
---- ----
. ____ _ __ _ _ . ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ ___ _ \ \ \ \ /\\ / ___'_ __ _ _(_)_ __ __ _ ___ _ \ \ \ \
......
...@@ -30,7 +30,7 @@ STS users can use the `Relaunch` button rather than the `Run` button to ensure t ...@@ -30,7 +30,7 @@ STS users can use the `Relaunch` button rather than the `Run` button to ensure t
=== Running as a Packaged Application === Running as a Packaged Application
If you use the Spring Boot Maven or Gradle plugins to create an executable jar, you can run your application using `java -jar`, as shown in the following example: If you use the Spring Boot Maven or Gradle plugins to create an executable jar, you can run your application using `java -jar`, as shown in the following example:
[indent=0,subs="attributes"] [indent=0,subs="verbatim"]
---- ----
$ java -jar target/myapplication-0.0.1-SNAPSHOT.jar $ java -jar target/myapplication-0.0.1-SNAPSHOT.jar
---- ----
...@@ -38,7 +38,7 @@ If you use the Spring Boot Maven or Gradle plugins to create an executable jar, ...@@ -38,7 +38,7 @@ If you use the Spring Boot Maven or Gradle plugins to create an executable jar,
It is also possible to run a packaged application with remote debugging support enabled. It is also possible to run a packaged application with remote debugging support enabled.
Doing so lets you attach a debugger to your packaged application, as shown in the following example: Doing so lets you attach a debugger to your packaged application, as shown in the following example:
[indent=0,subs="attributes"] [indent=0,subs="verbatim"]
---- ----
$ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \ $ java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n \
-jar target/myapplication-0.0.1-SNAPSHOT.jar -jar target/myapplication-0.0.1-SNAPSHOT.jar
...@@ -52,14 +52,14 @@ The Spring Boot Maven plugin includes a `run` goal that can be used to quickly c ...@@ -52,14 +52,14 @@ The Spring Boot Maven plugin includes a `run` goal that can be used to quickly c
Applications run in an exploded form, as they do in your IDE. Applications run in an exploded form, as they do in your IDE.
The following example shows a typical Maven command to run a Spring Boot application: The following example shows a typical Maven command to run a Spring Boot application:
[indent=0,subs="attributes"] [indent=0,subs="verbatim"]
---- ----
$ mvn spring-boot:run $ mvn spring-boot:run
---- ----
You might also want to use the `MAVEN_OPTS` operating system environment variable, as shown in the following example: You might also want to use the `MAVEN_OPTS` operating system environment variable, as shown in the following example:
[indent=0,subs="attributes"] [indent=0,subs="verbatim"]
---- ----
$ export MAVEN_OPTS=-Xmx1024m $ export MAVEN_OPTS=-Xmx1024m
---- ----
...@@ -71,14 +71,14 @@ You might also want to use the `MAVEN_OPTS` operating system environment variabl ...@@ -71,14 +71,14 @@ You might also want to use the `MAVEN_OPTS` operating system environment variabl
The Spring Boot Gradle plugin also includes a `bootRun` task that can be used to run your application in an exploded form. The Spring Boot Gradle plugin also includes a `bootRun` task that can be used to run your application in an exploded form.
The `bootRun` task is added whenever you apply the `org.springframework.boot` and `java` plugins and is shown in the following example: The `bootRun` task is added whenever you apply the `org.springframework.boot` and `java` plugins and is shown in the following example:
[indent=0,subs="attributes"] [indent=0,subs="verbatim"]
---- ----
$ gradle bootRun $ gradle bootRun
---- ----
You might also want to use the `JAVA_OPTS` operating system environment variable, as shown in the following example: You might also want to use the `JAVA_OPTS` operating system environment variable, as shown in the following example:
[indent=0,subs="attributes"] [indent=0,subs="verbatim"]
---- ----
$ export JAVA_OPTS=-Xmx1024m $ export JAVA_OPTS=-Xmx1024m
---- ----
......
...@@ -8,14 +8,14 @@ All of your application components (`@Component`, `@Service`, `@Repository`, `@C ...@@ -8,14 +8,14 @@ All of your application components (`@Component`, `@Service`, `@Repository`, `@C
The following example shows a `@Service` Bean that uses constructor injection to obtain a required `RiskAssessor` bean: The following example shows a `@Service` Bean that uses constructor injection to obtain a required `RiskAssessor` bean:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/using/springbeansanddependencyinjection/singleconstructor/MyAccountService.java[] include::{docs-java}/using/springbeansanddependencyinjection/singleconstructor/MyAccountService.java[]
---- ----
If a bean has more than one constructor, you'll need to mark the one you want Spring to use with `@Autowired`: If a bean has more than one constructor, you'll need to mark the one you want Spring to use with `@Autowired`:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/using/springbeansanddependencyinjection/multipleconstructors/MyAccountService.java[] include::{docs-java}/using/springbeansanddependencyinjection/multipleconstructors/MyAccountService.java[]
---- ----
......
...@@ -48,7 +48,7 @@ The following listing shows a typical layout: ...@@ -48,7 +48,7 @@ The following listing shows a typical layout:
The `MyApplication.java` file would declare the `main` method, along with the basic `@SpringBootApplication`, as follows: The `MyApplication.java` file would declare the `main` method, along with the basic `@SpringBootApplication`, as follows:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/using/structuringyourcode/locatingthemainclass/MyApplication.java[] include::{docs-java}/using/structuringyourcode/locatingthemainclass/MyApplication.java[]
---- ----
...@@ -7,7 +7,7 @@ A single `@SpringBootApplication` annotation can be used to enable those three f ...@@ -7,7 +7,7 @@ A single `@SpringBootApplication` annotation can be used to enable those three f
* `@ComponentScan`: enable `@Component` scan on the package where the application is located (see <<using#using.structuring-your-code,the best practices>>) * `@ComponentScan`: enable `@Component` scan on the package where the application is located (see <<using#using.structuring-your-code,the best practices>>)
* `@Configuration`: allow to register extra beans in the context or import additional configuration classes * `@Configuration`: allow to register extra beans in the context or import additional configuration classes
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/using/usingthespringbootapplicationannotation/springapplication/MyApplication.java[] include::{docs-java}/using/usingthespringbootapplicationannotation/springapplication/MyApplication.java[]
---- ----
...@@ -19,7 +19,7 @@ NOTE: `@SpringBootApplication` also provides aliases to customize the attributes ...@@ -19,7 +19,7 @@ NOTE: `@SpringBootApplication` also provides aliases to customize the attributes
None of these features are mandatory and you may choose to replace this single annotation by any of the features that it enables. None of these features are mandatory and you may choose to replace this single annotation by any of the features that it enables.
For instance, you may not want to use component scan or configuration properties scan in your application: For instance, you may not want to use component scan or configuration properties scan in your application:
[source,java,indent=0] [source,java,indent=0,subs="verbatim"]
---- ----
include::{docs-java}/using/usingthespringbootapplicationannotation/individualannotations/MyApplication.java[] include::{docs-java}/using/usingthespringbootapplicationannotation/individualannotations/MyApplication.java[]
---- ----
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment