Various properties can be specified inside your `application.properties` file, inside your `application.yml` file, or as command line switches.
Various properties can be specified inside your `application.properties` file, inside your `application.yml` file, or as command line switches.
This appendix provides a list of common Spring Boot properties and references to the underlying classes that consume them.
This appendix provides a list of common Spring Boot properties and references to the underlying classes that consume them.
TIP: Spring Boot provides various conversion mechanism with advanced value formatting, make sure to review <<spring-boot-features.adoc#boot-features-external-config-conversion, the properties conversion section>>.
TIP: Spring Boot provides various conversion mechanism with advanced value formatting, make sure to review <<spring-boot-features.adoc#features.external-config.typesafe-configuration-properties.conversion, the properties conversion section>>.
NOTE: Property contributions can come from additional jar files on your classpath, so you should not consider this an exhaustive list.
NOTE: Property contributions can come from additional jar files on your classpath, so you should not consider this an exhaustive list.
@@ -7,11 +7,11 @@ Spring Boot jars include metadata files that provide details of all supported co
...
@@ -7,11 +7,11 @@ Spring Boot jars include metadata files that provide details of all supported co
The files are designed to let IDE developers offer contextual help and "`code completion`" as users are working with `application.properties` or `application.yml` files.
The files are designed to let IDE developers offer contextual help and "`code completion`" as users are working with `application.properties` or `application.yml` files.
The majority of the metadata file is generated automatically at compile time by processing all items annotated with `@ConfigurationProperties`.
The majority of the metadata file is generated automatically at compile time by processing all items annotated with `@ConfigurationProperties`.
However, it is possible to <<configuration-metadata-additional-metadata,write part of the metadata manually>> for corner cases or more advanced use cases.
However, it is possible to <<configuration-metadata.annotation-processor.adding-additional-metadata,write part of the metadata manually>> for corner cases or more advanced use cases.
[[configuration-metadata-format]]
[[configuration-metadata.format]]
== Metadata Format
== Metadata Format
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:
...
@@ -98,7 +98,7 @@ For example, when a developer is configuring the configprop:spring.jpa.hibernate
...
@@ -98,7 +98,7 @@ For example, when a developer is configuring the configprop:spring.jpa.hibernate
[[configuration-metadata-group-attributes]]
[[configuration-metadata.format.group]]
=== Group Attributes
=== Group Attributes
The JSON object contained in the `groups` array can contain the attributes shown in the following table:
The JSON object contained in the `groups` array can contain the attributes shown in the following table:
...
@@ -139,7 +139,7 @@ The JSON object contained in the `groups` array can contain the attributes shown
...
@@ -139,7 +139,7 @@ The JSON object contained in the `groups` array can contain the attributes shown
[[configuration-metadata-property-attributes]]
[[configuration-metadata.format.property]]
=== Property Attributes
=== Property Attributes
The JSON object contained in the `properties` array can contain the attributes described in the following table:
The JSON object contained in the `properties` array can contain the attributes described in the following table:
...
@@ -254,7 +254,7 @@ Doing so is particularly useful when a `replacement` is provided.
...
@@ -254,7 +254,7 @@ Doing so is particularly useful when a `replacement` is provided.
[[configuration-metadata-hints-attributes]]
[[configuration-metadata.format.hints]]
=== Hint Attributes
=== Hint Attributes
The JSON object contained in the `hints` array can contain the attributes shown in the following table:
The JSON object contained in the `hints` array can contain the attributes shown in the following table:
...
@@ -317,7 +317,7 @@ The JSON object contained in the `providers` attribute of each `hint` element ca
...
@@ -317,7 +317,7 @@ The JSON object contained in the `providers` attribute of each `hint` element ca
[[configuration-metadata-repeated-items]]
[[configuration-metadata.format.repeated-items]]
=== Repeated Metadata Items
=== Repeated Metadata Items
Objects with the same "`property`" and "`group`" name can appear multiple times within a metadata file.
Objects with the same "`property`" and "`group`" name can appear multiple times within a metadata file.
For example, you could bind two separate classes to the same prefix, with each having potentially overlapping property names.
For example, you could bind two separate classes to the same prefix, with each having potentially overlapping property names.
...
@@ -325,7 +325,7 @@ While the same names appearing in the metadata multiple times should not be comm
...
@@ -325,7 +325,7 @@ While the same names appearing in the metadata multiple times should not be comm
[[configuration-metadata-providing-manual-hints]]
[[configuration-metadata.manual-hints]]
== Providing Manual Hints
== Providing Manual Hints
To improve the user experience and further assist the user in configuring a given property, you can provide additional metadata that:
To improve the user experience and further assist the user in configuring a given property, you can provide additional metadata that:
...
@@ -334,10 +334,10 @@ To improve the user experience and further assist the user in configuring a give
...
@@ -334,10 +334,10 @@ To improve the user experience and further assist the user in configuring a give
The `name` attribute of each hint refers to the `name` of a property.
The `name` attribute of each hint refers to the `name` of a property.
In the <<configuration-metadata-format,initial example shown earlier>>, we provide five values for the `spring.jpa.hibernate.ddl-auto` property: `none`, `validate`, `update`, `create`, and `create-drop`.
In the <<configuration-metadata.format,initial example shown earlier>>, we provide five values for the `spring.jpa.hibernate.ddl-auto` property: `none`, `validate`, `update`, `create`, and `create-drop`.
Each value may have a description as well.
Each value may have a description as well.
If your property is of type `Map`, you can provide hints for both the keys and the values (but not for the map itself).
If your property is of type `Map`, you can provide hints for both the keys and the values (but not for the map itself).
...
@@ -356,7 +356,7 @@ Assume a `sample.contexts` maps magic `String` values to an integer, as shown in
...
@@ -356,7 +356,7 @@ Assume a `sample.contexts` maps magic `String` values to an integer, as shown in
----
----
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-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.annotation-processor.adding-additional-metadata,the manual metadata of the module>>:
[source,json,indent=0]
[source,json,indent=0]
----
----
...
@@ -380,7 +380,7 @@ If your IDE supports it, this is by far the most effective approach to auto-comp
...
@@ -380,7 +380,7 @@ If your IDE supports it, this is by far the most effective approach to auto-comp
The **handle-as** provider lets you substitute the type of the property to a more high-level type.
The **handle-as** provider lets you substitute the type of the property to a more high-level type.
This typically happens when the property has a `java.lang.String` type, because you do not want your configuration classes to rely on classes that may not be on the classpath.
This typically happens when the property has a `java.lang.String` type, because you do not want your configuration classes to rely on classes that may not be on the classpath.
...
@@ -553,9 +553,9 @@ It is actually used internally as a `org.springframework.core.io.Resource` but c
...
@@ -553,9 +553,9 @@ It is actually used internally as a `org.springframework.core.io.Resource` but c
The **spring-profile-name** provider auto-completes the Spring profiles that are defined in the configuration of the current project.
The **spring-profile-name** provider auto-completes the Spring profiles that are defined in the configuration of the current project.
...
@@ -702,14 +702,14 @@ The following metadata snippet corresponds to the standard `spring.profiles.acti
...
@@ -702,14 +702,14 @@ The following metadata snippet corresponds to the standard `spring.profiles.acti
[[configuration-metadata-annotation-processor]]
[[configuration-metadata.annotation-processor]]
== Generating Your Own Metadata by Using the Annotation Processor
== Generating Your Own Metadata by Using the Annotation Processor
You can easily generate your own configuration metadata file from items annotated with `@ConfigurationProperties` by using the `spring-boot-configuration-processor` jar.
You can easily generate your own configuration metadata file from items annotated with `@ConfigurationProperties` by using the `spring-boot-configuration-processor` jar.
The jar includes a Java annotation processor which is invoked as your project is compiled.
The jar includes a Java annotation processor which is invoked as your project is compiled.
The processor picks up both classes and methods that are annotated with `@ConfigurationProperties`.
The processor picks up both classes and methods that are annotated with `@ConfigurationProperties`.
...
@@ -807,7 +807,7 @@ The annotation processor applies a number of heuristics to extract the default v
...
@@ -807,7 +807,7 @@ The annotation processor applies a number of heuristics to extract the default v
Default values have to be provided statically. In particular, do not refer to a constant defined in another class.
Default values have to be provided statically. In particular, do not refer to a constant defined in another class.
Also, the annotation processor cannot auto-detect default values for ``Enum``s and ``Collections``s.
Also, the annotation processor cannot auto-detect default values for ``Enum``s and ``Collections``s.
For cases where the default value could not be detected, <<configuration-metadata-additional-metadata,manual metadata>> should be provided.
For cases where the default value could not be detected, <<configuration-metadata.annotation-processor.adding-additional-metadata,manual metadata>> should be provided.
@@ -831,7 +831,7 @@ Consider the following example:
...
@@ -831,7 +831,7 @@ Consider the following example:
}
}
----
----
In order to document default values for properties in the class above, you could add the following content to <<configuration-metadata-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.annotation-processor.adding-additional-metadata,the manual metadata of the module>>:
[source,json,indent=0]
[source,json,indent=0]
----
----
...
@@ -851,7 +851,7 @@ NOTE: Only the `name` of the property is required to document additional metadat
...
@@ -851,7 +851,7 @@ NOTE: Only the `name` of the property is required to document additional metadat
Spring Boot's configuration file handling is quite flexible, and it is often the case that properties may exist that are not bound to a `@ConfigurationProperties` bean.
Spring Boot's configuration file handling is quite flexible, and it is often the case that properties may exist that are not bound to a `@ConfigurationProperties` bean.
You may also need to tune some attributes of an existing key.
You may also need to tune some attributes of an existing key.
@@ -7,7 +7,7 @@ This appendix provides details of the dependencies that are managed by Spring Bo
...
@@ -7,7 +7,7 @@ This appendix provides details of the dependencies that are managed by Spring Bo
[[dependency-versions-coordinates]]
[[dependency-versions.coordinates]]
== Managed Dependency Coordinates
== Managed Dependency Coordinates
The following table provides details of all of the dependency versions that are provided by Spring Boot in its CLI (Command Line Interface), Maven dependency management, and Gradle plugin.
The following table provides details of all of the dependency versions that are provided by Spring Boot in its CLI (Command Line Interface), Maven dependency management, and Gradle plugin.
@@ -10,7 +10,7 @@ If you need to create executable jars from a different build system or if you ar
...
@@ -10,7 +10,7 @@ If you need to create executable jars from a different build system or if you ar
[[executable-jar-nested-jars]]
[[executable-jar.nested-jars]]
== Nested JARs
== Nested JARs
Java does not provide any standard way to load nested jar files (that is, jar files that are themselves contained within a jar).
Java does not provide any standard way to load nested jar files (that is, jar files that are themselves contained within a jar).
This can be problematic if you need to distribute a self-contained application that can be run from the command line without unpacking.
This can be problematic if you need to distribute a self-contained application that can be run from the command line without unpacking.
...
@@ -23,7 +23,7 @@ Spring Boot takes a different approach and lets you actually nest jars directly.
...
@@ -23,7 +23,7 @@ Spring Boot takes a different approach and lets you actually nest jars directly.
[[executable-jar-jar-file-structure]]
[[executable-jar.nested-jars.jar-structure]]
=== The Executable Jar File Structure
=== The Executable Jar File Structure
Spring Boot Loader-compatible jar files should be structured in the following way:
Spring Boot Loader-compatible jar files should be structured in the following way:
...
@@ -53,7 +53,7 @@ Dependencies should be placed in a nested `BOOT-INF/lib` directory.
...
@@ -53,7 +53,7 @@ Dependencies should be placed in a nested `BOOT-INF/lib` directory.
[[executable-jar-war-file-structure]]
[[executable-jar.nested-jars.war-structure]]
=== The Executable War File Structure
=== The Executable War File Structure
Spring Boot Loader-compatible war files should be structured in the following way:
Spring Boot Loader-compatible war files should be structured in the following way:
...
@@ -87,7 +87,7 @@ Any dependencies that are required when running embedded but are not required wh
...
@@ -87,7 +87,7 @@ Any dependencies that are required when running embedded but are not required wh
[[executable-jar-war-index-files]]
[[executable-jar.nested-jars.index-files]]
=== Index Files
=== Index Files
Spring Boot Loader-compatible jar and war archives can include additional index files under the `BOOT-INF/` directory.
Spring Boot Loader-compatible jar and war archives can include additional index files under the `BOOT-INF/` directory.
A `classpath.idx` file can be provided for both jars and wars, and it provides the ordering that jars should be added to the classpath.
A `classpath.idx` file can be provided for both jars and wars, and it provides the ordering that jars should be added to the classpath.
...
@@ -98,7 +98,7 @@ These files, however, are _not_ parsed internally as YAML and they must be writt
...
@@ -98,7 +98,7 @@ These files, however, are _not_ parsed internally as YAML and they must be writt
[[executable-jar-war-index-files-classpath]]
[[executable-jar.nested-jars.classpath-index]]
=== Classpath Index
=== Classpath Index
The classpath index file can be provided in `BOOT-INF/classpath.idx`.
The classpath index file can be provided in `BOOT-INF/classpath.idx`.
It provides a list of jar names (including the directory) in the order that they should be added to the classpath.
It provides a list of jar names (including the directory) in the order that they should be added to the classpath.
...
@@ -130,7 +130,7 @@ The index file would look like this:
...
@@ -130,7 +130,7 @@ The index file would look like this:
[[executable-jar-war-index-files-layers]]
[[executable-jar.nested-jars.layer-index]]
=== Layer Index
=== Layer Index
The layers index file can be provided in `BOOT-INF/layers.idx`.
The layers index file can be provided in `BOOT-INF/layers.idx`.
It provides a list of layers and the parts of the jar that should be contained within them.
It provides a list of layers and the parts of the jar that should be contained within them.
...
@@ -154,7 +154,7 @@ A typical example of a layers index would be:
...
@@ -154,7 +154,7 @@ A typical example of a layers index would be:
[[executable-jar-jarfile]]
[[executable-jar.jarfile-class]]
== Spring Boot's "`JarFile`" Class
== Spring Boot's "`JarFile`" Class
The core class used to support loading nested jars is `org.springframework.boot.loader.jar.JarFile`.
The core class used to support loading nested jars is `org.springframework.boot.loader.jar.JarFile`.
It lets you load jar content from a standard jar file or from nested child jar data.
It lets you load jar content from a standard jar file or from nested child jar data.
...
@@ -181,7 +181,7 @@ We do not need to unpack the archive, and we do not need to read all entry data
...
@@ -181,7 +181,7 @@ We do not need to unpack the archive, and we do not need to read all entry data
[[executable-jar-jarfile-compatibility]]
[[executable-jar.jarfile-class.compatibilty]]
=== Compatibility with the Standard Java "`JarFile`"
=== Compatibility with the Standard Java "`JarFile`"
Spring Boot Loader strives to remain compatible with existing code and libraries.
Spring Boot Loader strives to remain compatible with existing code and libraries.
`org.springframework.boot.loader.jar.JarFile` extends from `java.util.jar.JarFile` and should work as a drop-in replacement.
`org.springframework.boot.loader.jar.JarFile` extends from `java.util.jar.JarFile` and should work as a drop-in replacement.
...
@@ -189,7 +189,7 @@ The `getURL()` method returns a `URL` that opens a connection compatible with `j
...
@@ -189,7 +189,7 @@ The `getURL()` method returns a `URL` that opens a connection compatible with `j
[[executable-jar-launching]]
[[executable-jar.launching]]
== Launching Executable Jars
== Launching Executable Jars
The `org.springframework.boot.loader.Launcher` class is a special bootstrap class that is used as an executable jar's main entry point.
The `org.springframework.boot.loader.Launcher` class is a special bootstrap class that is used as an executable jar's main entry point.
It is the actual `Main-Class` in your jar file, and it is used to setup an appropriate `URLClassLoader` and ultimately call your `main()` method.
It is the actual `Main-Class` in your jar file, and it is used to setup an appropriate `URLClassLoader` and ultimately call your `main()` method.
...
@@ -204,7 +204,7 @@ You can add additional locations by setting an environment variable called `LOAD
...
@@ -204,7 +204,7 @@ You can add additional locations by setting an environment variable called `LOAD
[[executable-jar-launcher-manifest]]
[[executable-jar.launching.manifest]]
=== Launcher Manifest
=== Launcher Manifest
You need to specify an appropriate `Launcher` as the `Main-Class` attribute of `META-INF/MANIFEST.MF`.
You need to specify an appropriate `Launcher` as the `Main-Class` attribute of `META-INF/MANIFEST.MF`.
The actual class that you want to launch (that is, the class that contains a `main` method) should be specified in the `Start-Class` attribute.
The actual class that you want to launch (that is, the class that contains a `main` method) should be specified in the `Start-Class` attribute.
...
@@ -230,7 +230,7 @@ The classpath is deduced from the nested jars.
...
@@ -230,7 +230,7 @@ The classpath is deduced from the nested jars.
[[executable-jar-property-launcher-features]]
[[executable-jar.property-launcher]]
== PropertiesLauncher Features
== PropertiesLauncher Features
`PropertiesLauncher` has a few special features that can be enabled with external properties (System properties, environment variables, manifest entries, or `loader.properties`).
`PropertiesLauncher` has a few special features that can be enabled with external properties (System properties, environment variables, manifest entries, or `loader.properties`).
The following table describes these properties:
The following table describes these properties:
...
@@ -314,7 +314,7 @@ The following rules apply to working with `PropertiesLauncher`:
...
@@ -314,7 +314,7 @@ The following rules apply to working with `PropertiesLauncher`:
[[executable-jar-restrictions]]
[[executable-jar.restrictions]]
== Executable Jar Restrictions
== Executable Jar Restrictions
You need to consider the following restrictions when working with a Spring Boot Loader packaged application:
You need to consider the following restrictions when working with a Spring Boot Loader packaged application:
...
@@ -337,7 +337,7 @@ For this reason, you should consider a different logging implementation.
...
@@ -337,7 +337,7 @@ For this reason, you should consider a different logging implementation.
[[executable-jar-alternatives]]
[[executable-jar.alternatives]]
== Alternative Single Jar Solutions
== Alternative Single Jar Solutions
If the preceding restrictions mean that you cannot use Spring Boot Loader, consider the following alternatives:
If the preceding restrictions mean that you cannot use Spring Boot Loader, consider the following alternatives:
@@ -7,7 +7,7 @@ This appendix describes the `@…Test` auto-configuration annotations that Sprin
...
@@ -7,7 +7,7 @@ This appendix describes the `@…Test` auto-configuration annotations that Sprin
[[test-auto-configuration-slices]]
[[test-auto-configuration.slices]]
== Test Slices
== Test Slices
The following table lists the various `@…Test` annotations that can be used to test slices of your application and the auto-configuration that they import by default:
The following table lists the various `@…Test` annotations that can be used to test slices of your application and the auto-configuration that they import by default:
Spring Boot provides build tool plugins for Maven and Gradle.
Spring Boot provides build tool plugins for Maven and Gradle.
The plugins offer a variety of features, including the packaging of executable jars.
The plugins offer a variety of features, including the packaging of executable jars.
This section provides more details on both plugins as well as some help should you need to extend an unsupported build system.
This section provides more details on both plugins as well as some help should you need to extend an unsupported build system.
If you are just getting started, you might want to read "`<<using-spring-boot.adoc#using-boot-build-systems>>`" from the "`<<using-spring-boot.adoc#using-boot>>`" section first.
If you are just getting started, you might want to read "`<<using-spring-boot.adoc#using.build-systems>>`" from the "`<<using-spring-boot.adoc#using>>`" section first.
[[build-tool-plugins-maven-plugin]]
[[build-tool-plugins.maven]]
== Spring Boot Maven Plugin
== Spring Boot Maven Plugin
The Spring Boot Maven Plugin provides Spring Boot support in Maven, letting you package executable jar or war archives and run an application "`in-place`".
The Spring Boot Maven Plugin provides Spring Boot support in Maven, letting you package executable jar or war archives and run an application "`in-place`".
To use it, you must use Maven 3.2 (or later).
To use it, you must use Maven 3.2 (or later).
...
@@ -21,7 +21,7 @@ Please refer to the plugin's documentation to learn more:
...
@@ -21,7 +21,7 @@ Please refer to the plugin's documentation to learn more:
[[build-tool-plugins-gradle-plugin]]
[[build-tool-plugins.gradle]]
== Spring Boot Gradle Plugin
== Spring Boot Gradle Plugin
The Spring Boot Gradle Plugin provides Spring Boot support in Gradle, letting you package executable jar or war archives, run Spring Boot applications, and use the dependency management provided by `spring-boot-dependencies`.
The Spring Boot Gradle Plugin provides Spring Boot support in Gradle, letting you package executable jar or war archives, run Spring Boot applications, and use the dependency management provided by `spring-boot-dependencies`.
It requires Gradle 6.8 or 7.x.
It requires Gradle 6.8 or 7.x.
...
@@ -32,7 +32,7 @@ Please refer to the plugin's documentation to learn more:
...
@@ -32,7 +32,7 @@ Please refer to the plugin's documentation to learn more:
[[build-tool-plugins-antlib]]
[[build-tool-plugins.antlib]]
== Spring Boot AntLib Module
== Spring Boot AntLib Module
The Spring Boot AntLib module provides basic Spring Boot support for Apache Ant.
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.
...
@@ -54,20 +54,20 @@ You need to remember to start Ant using the `-lib` option, as shown in the follo
...
@@ -54,20 +54,20 @@ You need to remember to start Ant using the `-lib` option, as shown in the follo
$ ant -lib <directory containing spring-boot-antlib-{spring-boot-version}.jar>
$ ant -lib <directory containing spring-boot-antlib-{spring-boot-version}.jar>
----
----
TIP: The "`Using Spring Boot`" section includes a more complete example of <<using-spring-boot.adoc#using-boot-ant, using Apache Ant with `spring-boot-antlib`>>.
TIP: The "`Using Spring Boot`" section includes a more complete example of <<using-spring-boot.adoc#using.build-systems.ant, using Apache Ant with `spring-boot-antlib`>>.
[[spring-boot-ant-tasks]]
[[build-tool-plugins.antlib.tasks]]
=== Spring Boot Ant Tasks
=== Spring Boot Ant Tasks
Once the `spring-boot-antlib` namespace has been declared, the following additional tasks are available:
Once the `spring-boot-antlib` namespace has been declared, the following additional tasks are available:
* <<spring-boot-ant-exejar>>
* <<build-tool-plugins.antlib.tasks.exejar>>
* <<spring-boot-ant-findmainclass>>
* <<build-tool-plugins.antlib.findmainclass>>
[[spring-boot-ant-exejar]]
[[build-tool-plugins.antlib.tasks.exejar]]
==== Using the "`exejar`" Task
==== Using the "`exejar`" Task
You can use the `exejar` task to create a Spring Boot executable jar.
You can use the `exejar` task to create a Spring Boot executable jar.
The following attributes are supported by the task:
The following attributes are supported by the task:
...
@@ -104,7 +104,7 @@ The following nested elements can be used with the task:
...
@@ -104,7 +104,7 @@ The following nested elements can be used with the task:
[[spring-boot-ant-exejar-examples]]
[[build-tool-plugins.antlib.tasks.examples]]
==== Examples
==== Examples
This section shows two examples of Ant tasks.
This section shows two examples of Ant tasks.
...
@@ -134,7 +134,7 @@ This section shows two examples of Ant tasks.
...
@@ -134,7 +134,7 @@ This section shows two examples of Ant tasks.
[[spring-boot-ant-findmainclass]]
[[build-tool-plugins.antlib.findmainclass]]
=== Using the "`findmainclass`" Task
=== Using the "`findmainclass`" Task
The `findmainclass` task is used internally by `exejar` to locate a class declaring a `main`.
The `findmainclass` task is used internally by `exejar` to locate a class declaring a `main`.
If necessary, you can also use this task directly in your build.
If necessary, you can also use this task directly in your build.
...
@@ -159,7 +159,7 @@ The following attributes are supported:
...
@@ -159,7 +159,7 @@ The following attributes are supported:
This section contains three examples of using `findmainclass`.
This section contains three examples of using `findmainclass`.
...
@@ -183,7 +183,7 @@ This section contains three examples of using `findmainclass`.
...
@@ -183,7 +183,7 @@ This section contains three examples of using `findmainclass`.
[[build-tool-plugins-other-build-systems]]
[[build-tool-plugins.other-build-systems]]
== Supporting Other Build Systems
== Supporting Other Build Systems
If you want to use a build tool other than Maven, Gradle, or Ant, you likely need to develop your own plugin.
If you want to use a build tool other than Maven, Gradle, or Ant, you likely need to develop your own plugin.
Executable jars need to follow a specific format and certain entries need to be written in an uncompressed form (see the "`<<appendix-executable-jar-format.adoc#executable-jar, executable jar format>>`" section in the appendix for details).
Executable jars need to follow a specific format and certain entries need to be written in an uncompressed form (see the "`<<appendix-executable-jar-format.adoc#executable-jar, executable jar format>>`" section in the appendix for details).
...
@@ -193,7 +193,7 @@ If you need to, you may use this library directly.
...
@@ -193,7 +193,7 @@ If you need to, you may use this library directly.
If you do not use `Repackager.setMainClass()` to specify a main class, the repackager uses https://asm.ow2.io/[ASM] to read class files and tries to find a suitable class with a `public static void main(String[] args)` method.
If you do not use `Repackager.setMainClass()` to specify a main class, the repackager uses https://asm.ow2.io/[ASM] to read class files and tries to find a suitable class with a `public static void main(String[] args)` method.
An exception is thrown if more than one candidate is found.
An exception is thrown if more than one candidate is found.
The following example shows a typical repackage implementation:
The following example shows a typical repackage implementation:
...
@@ -237,7 +237,7 @@ The following example shows a typical repackage implementation:
...
@@ -237,7 +237,7 @@ The following example shows a typical repackage implementation:
[[build-tool-plugins-whats-next]]
[[build-tool-plugins.whats-next]]
== What to Read Next
== What to Read Next
If you are interested in how the build tool plugins work, you can look at the {spring-boot-code}/spring-boot-project/spring-boot-tools[`spring-boot-tools`] module on GitHub.
If you are interested in how the build tool plugins work, you can look at the {spring-boot-code}/spring-boot-project/spring-boot-tools[`spring-boot-tools`] module on GitHub.
More technical details of the executable jar format are covered in <<appendix-executable-jar-format#executable-jar,the appendix>>.
More technical details of the executable jar format are covered in <<appendix-executable-jar-format#executable-jar,the appendix>>.
@@ -9,7 +9,7 @@ This section covers some of the more common deployment scenarios.
...
@@ -9,7 +9,7 @@ This section covers some of the more common deployment scenarios.
[[containers-deployment]]
[[deployment.containers]]
== Deploying to Containers
== Deploying to Containers
If you are running your application from a container, you can use an executable jar, but it is also often an advantage to explode it and run it in a different way.
If you are running your application from a container, you can use an executable jar, but it is also often an advantage to explode it and run it in a different way.
Certain PaaS implementations may also choose to unpack archives before they run.
Certain PaaS implementations may also choose to unpack archives before they run.
...
@@ -36,11 +36,11 @@ Once you have unpacked the jar file, you can also get an extra boost to startup
...
@@ -36,11 +36,11 @@ Once you have unpacked the jar file, you can also get an extra boost to startup
NOTE: Using the `JarLauncher` over the application's main method has the added benefit of a predictable classpath order.
NOTE: Using the `JarLauncher` over the application's main method has the added benefit of a predictable classpath order.
The jar contains a `classpath.idx` file which is used by the `JarLauncher` when constructing the classpath.
The jar contains a `classpath.idx` file which is used by the `JarLauncher` when constructing the classpath.
More efficient container images can also be created by <<spring-boot-features.adoc#boot-features-container-images-docker,creating separate layers>> for your dependencies and application classes and resources (which normally change more frequently).
More efficient container images can also be created by <<spring-boot-features.adoc#features.container-images.building.dockerfiles,creating separate layers>> for your dependencies and application classes and resources (which normally change more frequently).
[[cloud-deployment]]
[[deployment.cloud]]
== Deploying to the Cloud
== Deploying to the Cloud
Spring Boot's executable jars are ready-made for most popular cloud PaaS (Platform-as-a-Service) providers.
Spring Boot's executable jars are ready-made for most popular cloud PaaS (Platform-as-a-Service) providers.
These providers tend to require that you "`bring your own container`".
These providers tend to require that you "`bring your own container`".
...
@@ -55,11 +55,11 @@ It minimizes divergence between development and production environments.
...
@@ -55,11 +55,11 @@ It minimizes divergence between development and production environments.
Ideally, your application, like a Spring Boot executable jar, has everything that it needs to run packaged within it.
Ideally, your application, like a Spring Boot executable jar, has everything that it needs to run packaged within it.
In this section, we look at what it takes to get the <<getting-started.adoc#getting-started-first-application, application that we developed>> in the "`Getting Started`" section up and running in the Cloud.
In this section, we look at what it takes to get the <<getting-started.adoc#getting-started.first-application, application that we developed>> in the "`Getting Started`" section up and running in the Cloud.
[[cloud-deployment-cloud-foundry]]
[[deployment.cloud.cloud-foundry]]
=== Cloud Foundry
=== Cloud Foundry
Cloud Foundry provides default buildpacks that come into play if no other buildpack is specified.
Cloud Foundry provides default buildpacks that come into play if no other buildpack is specified.
The Cloud Foundry https://github.com/cloudfoundry/java-buildpack[Java buildpack] has excellent support for Spring applications, including Spring Boot.
The Cloud Foundry https://github.com/cloudfoundry/java-buildpack[Java buildpack] has excellent support for Spring applications, including Spring Boot.
...
@@ -127,7 +127,7 @@ In the preceding example, you could find it at `\https://acloudyspringtime.cfapp
...
@@ -127,7 +127,7 @@ In the preceding example, you could find it at `\https://acloudyspringtime.cfapp
By default, metadata about the running application as well as service connection information is exposed to the application as environment variables (for example: `$VCAP_SERVICES`).
By default, metadata about the running application as well as service connection information is exposed to the application as environment variables (for example: `$VCAP_SERVICES`).
This architecture decision is due to Cloud Foundry's polyglot (any language and platform can be supported as a buildpack) nature.
This architecture decision is due to Cloud Foundry's polyglot (any language and platform can be supported as a buildpack) nature.
...
@@ -160,16 +160,16 @@ TIP: The https://github.com/pivotal-cf/java-cfenv/[Java CFEnv] project is a bett
...
@@ -160,16 +160,16 @@ TIP: The https://github.com/pivotal-cf/java-cfenv/[Java CFEnv] project is a bett
[[cloud-deployment-kubernetes]]
[[deployment.cloud.kubernetes]]
=== Kubernetes
=== Kubernetes
Spring Boot auto-detects Kubernetes deployment environments by checking the environment for `"*_SERVICE_HOST"` and `"*_SERVICE_PORT"` variables.
Spring Boot auto-detects Kubernetes deployment environments by checking the environment for `"*_SERVICE_HOST"` and `"*_SERVICE_PORT"` variables.
You can override this detection with the configprop:spring.main.cloud-platform[] configuration property.
You can override this detection with the configprop:spring.main.cloud-platform[] configuration property.
Spring Boot helps you to <<spring-boot-features.adoc#boot-features-application-availability,manage the state of your application>> and export it with <<production-ready-features.adoc#production-ready-kubernetes-probes, HTTP Kubernetes Probes using Actuator>>.
Spring Boot helps you to <<spring-boot-features.adoc#features.spring-application.application-availability,manage the state of your application>> and export it with <<production-ready-features.adoc#actuator.endpoints.kubernetes-probes, HTTP Kubernetes Probes using Actuator>>.
When Kubernetes deletes an application instance, the shutdown process involves several subsystems concurrently: shutdown hooks, unregistering the service, removing the instance from the load-balancer...
When Kubernetes deletes an application instance, the shutdown process involves several subsystems concurrently: shutdown hooks, unregistering the service, removing the instance from the load-balancer...
Because this shutdown processing happens in parallel (and due to the nature of distributed systems), there is a window during which traffic can be routed to a pod that has also begun its shutdown processing.
Because this shutdown processing happens in parallel (and due to the nature of distributed systems), there is a window during which traffic can be routed to a pod that has also begun its shutdown processing.
...
@@ -190,11 +190,11 @@ spec:
...
@@ -190,11 +190,11 @@ spec:
command: ["sh", "-c", "sleep 10"]
command: ["sh", "-c", "sleep 10"]
----
----
Once the pre-stop hook has completed, SIGTERM will be sent to the container and <<spring-boot-features#boot-features-graceful-shutdown,graceful shutdown>> will begin, allowing any remaining in-flight requests to complete.
Once the pre-stop hook has completed, SIGTERM will be sent to the container and <<spring-boot-features#features.graceful-shutdown,graceful shutdown>> will begin, allowing any remaining in-flight requests to complete.
[[cloud-deployment-heroku]]
[[deployment.cloud.heroku]]
=== Heroku
=== Heroku
Heroku is another popular PaaS platform.
Heroku is another popular PaaS platform.
To customize Heroku builds, you provide a `Procfile`, which provides the incantation required to deploy an application.
To customize Heroku builds, you provide a `Procfile`, which provides the incantation required to deploy an application.
...
@@ -263,7 +263,7 @@ For more details, refer to https://devcenter.heroku.com/articles/deploying-sprin
...
@@ -263,7 +263,7 @@ For more details, refer to https://devcenter.heroku.com/articles/deploying-sprin
[[cloud-deployment-openshift]]
[[deployment.cloud.openshift]]
=== OpenShift
=== OpenShift
https://www.openshift.com/[OpenShift] has many resources describing how to deploy Spring Boot applications, including:
https://www.openshift.com/[OpenShift] has many resources describing how to deploy Spring Boot applications, including:
...
@@ -274,7 +274,7 @@ https://www.openshift.com/[OpenShift] has many resources describing how to deplo
...
@@ -274,7 +274,7 @@ https://www.openshift.com/[OpenShift] has many resources describing how to deplo
[[cloud-deployment-aws]]
[[deployment.cloud.aws]]
=== Amazon Web Services (AWS)
=== Amazon Web Services (AWS)
Amazon Web Services offers multiple ways to install Spring Boot-based applications, either as traditional web applications (war) or as executable jar files with an embedded web server.
Amazon Web Services offers multiple ways to install Spring Boot-based applications, either as traditional web applications (war) or as executable jar files with an embedded web server.
The options include:
The options include:
...
@@ -290,14 +290,14 @@ In this document, we describe to approach using AWS Elastic Beanstalk.
...
@@ -290,14 +290,14 @@ In this document, we describe to approach using AWS Elastic Beanstalk.
[[cloud-deployment-aws-beanstalk]]
[[deployment.cloud.aws.beanstalk]]
==== AWS Elastic Beanstalk
==== AWS Elastic Beanstalk
As described in the official https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Java.html[Elastic Beanstalk Java guide], there are two main options to deploy a Java application.
As described in the official https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Java.html[Elastic Beanstalk Java guide], there are two main options to deploy a Java application.
You can either use the "`Tomcat Platform`" or the "`Java SE platform`".
You can either use the "`Tomcat Platform`" or the "`Java SE platform`".
This option applies to Spring Boot projects that produce a jar file and run an embedded web container.
This option applies to Spring Boot projects that produce a jar file and run an embedded web container.
Elastic Beanstalk environments run an nginx instance on port 80 to proxy the actual application, running on port 5000.
Elastic Beanstalk environments run an nginx instance on port 80 to proxy the actual application, running on port 5000.
...
@@ -347,14 +347,14 @@ You can also create single instance environments by using the CLI and the follow
...
@@ -347,14 +347,14 @@ You can also create single instance environments by using the CLI and the follow
[[cloud-deployment-aws-summary]]
[[deployment.cloud.aws.summary]]
==== Summary
==== Summary
This is one of the easiest ways to get to AWS, but there are more things to cover, such as how to integrate Elastic Beanstalk into any CI / CD tool, use the Elastic Beanstalk Maven plugin instead of the CLI, and others.
This is one of the easiest ways to get to AWS, but there are more things to cover, such as how to integrate Elastic Beanstalk into any CI / CD tool, use the Elastic Beanstalk Maven plugin instead of the CLI, and others.
There is a https://exampledriven.wordpress.com/2017/01/09/spring-boot-aws-elastic-beanstalk-example/[blog post] covering these topics more in detail.
There is a https://exampledriven.wordpress.com/2017/01/09/spring-boot-aws-elastic-beanstalk-example/[blog post] covering these topics more in detail.
[[cloud-deployment-boxfuse]]
[[deployment.cloud.boxfuse]]
=== Boxfuse and Amazon Web Services
=== Boxfuse and Amazon Web Services
https://boxfuse.com/[Boxfuse] works by turning your Spring Boot executable jar or war into a minimal VM image that can be deployed unchanged either on VirtualBox or on AWS.
https://boxfuse.com/[Boxfuse] works by turning your Spring Boot executable jar or war into a minimal VM image that can be deployed unchanged either on VirtualBox or on AWS.
Boxfuse comes with deep integration for Spring Boot and uses the information from your Spring Boot configuration file to automatically configure ports and health check URLs.
Boxfuse comes with deep integration for Spring Boot and uses the information from your Spring Boot configuration file to automatically configure ports and health check URLs.
...
@@ -402,7 +402,7 @@ See the blog post on https://boxfuse.com/blog/spring-boot-ec2.html[deploying Spr
...
@@ -402,7 +402,7 @@ See the blog post on https://boxfuse.com/blog/spring-boot-ec2.html[deploying Spr
[[cloud-deployment-gae]]
[[deployment.cloud.google]]
=== Google Cloud
=== Google Cloud
Google Cloud has several options that can be used to launch Spring Boot applications.
Google Cloud has several options that can be used to launch Spring Boot applications.
The easiest to get started with is probably App Engine, but you could also find ways to run Spring Boot in a container with Container Engine or on a virtual machine with Compute Engine.
The easiest to get started with is probably App Engine, but you could also find ways to run Spring Boot in a container with Container Engine or on a virtual machine with Compute Engine.
...
@@ -458,10 +458,10 @@ Then deploy with `mvn appengine:deploy` (if you need to authenticate first, the
...
@@ -458,10 +458,10 @@ Then deploy with `mvn appengine:deploy` (if you need to authenticate first, the
[[deployment-install]]
[[deployment.installing]]
== Installing Spring Boot Applications
== Installing Spring Boot Applications
In addition to running Spring Boot applications by using `java -jar`, it is also possible to make fully executable applications for Unix systems.
In addition to running Spring Boot applications by using `java -jar`, it is also possible to make fully executable applications for Unix systems.
A fully executable jar can be executed like any other executable binary or it can be <<deployment-service,registered with `init.d` or `systemd`>>.
A fully executable jar can be executed like any other executable binary or it can be <<deployment.installing.nix-services,registered with `init.d` or `systemd`>>.
This helps when installing and managing Spring Boot applications in common production environments.
This helps when installing and managing Spring Boot applications in common production environments.
CAUTION: Fully executable jars work by embedding an extra script at the front of the file.
CAUTION: Fully executable jars work by embedding an extra script at the front of the file.
...
@@ -500,22 +500,22 @@ The directory containing the jar is used as your application's working directory
...
@@ -500,22 +500,22 @@ The directory containing the jar is used as your application's working directory
The default script supports most Linux distributions and is tested on CentOS and Ubuntu.
The default script supports most Linux distributions and is tested on CentOS and Ubuntu.
Other platforms, such as OS X and FreeBSD, require the use of a custom `embeddedLaunchScript`.
Other platforms, such as OS X and FreeBSD, require the use of a custom `embeddedLaunchScript`.
[[deployment-service]]
[[deployment.installing.nix-services]]
=== Unix/Linux Services
=== Unix/Linux Services
Spring Boot application can be easily started as Unix/Linux services by using either `init.d` or `systemd`.
Spring Boot application can be easily started as Unix/Linux services by using either `init.d` or `systemd`.
[[deployment-initd-service]]
[[deployment.installing.nix-services.init-d]]
==== Installation as an init.d Service (System V)
==== Installation as an init.d Service (System V)
If you configured Spring Boot's Maven or Gradle plugin to generate a <<deployment-install, fully executable jar>>, and you do not use a custom `embeddedLaunchScript`, your application can be used as an `init.d` service.
If you configured Spring Boot's Maven or Gradle plugin to generate a <<deployment.installing, fully executable jar>>, and you do not use a custom `embeddedLaunchScript`, your application can be used as an `init.d` service.
To do so, symlink the jar to `init.d` to support the standard `start`, `stop`, `restart`, and `status` commands.
To do so, symlink the jar to `init.d` to support the standard `start`, `stop`, `restart`, and `status` commands.
The script supports the following features:
The script supports the following features:
...
@@ -551,7 +551,7 @@ For example, on Debian, you could use the following command:
...
@@ -551,7 +551,7 @@ For example, on Debian, you could use the following command:
NOTE: The following is a set of guidelines on how to secure a Spring Boot application that runs as an init.d service.
NOTE: The following is a set of guidelines on how to secure a Spring Boot application that runs as an init.d service.
It is not intended to be an exhaustive list of everything that should be done to harden an application and the environment in which it runs.
It is not intended to be an exhaustive list of everything that should be done to harden an application and the environment in which it runs.
...
@@ -602,7 +602,7 @@ Use `chmod` so that the file can only be read by the owner and use `chown` to ma
...
@@ -602,7 +602,7 @@ Use `chmod` so that the file can only be read by the owner and use `chown` to ma
[[deployment-systemd-service]]
[[deployment.installing.nix-services.system-d]]
==== Installation as a systemd Service
==== Installation as a systemd Service
`systemd` is the successor of the System V init system and is now being used by many modern Linux distributions.
`systemd` is the successor of the System V init system and is now being used by many modern Linux distributions.
Although you can continue to use `init.d` scripts with `systemd`, it is also possible to launch Spring Boot applications by using `systemd` '`service`' scripts.
Although you can continue to use `init.d` scripts with `systemd`, it is also possible to launch Spring Boot applications by using `systemd` '`service`' scripts.
...
@@ -643,7 +643,7 @@ Refer to `man systemctl` for more details.
...
@@ -643,7 +643,7 @@ Refer to `man systemctl` for more details.
For items of the script that need to be customized _after_ the jar has been written, you can use environment variables or a <<deployment-script-customization-conf-file, config file>>.
For items of the script that need to be customized _after_ the jar has been written, you can use environment variables or a <<deployment-script-customization-conf-file, config file>>.
...
@@ -838,11 +838,11 @@ For example, a jar named `/var/myapp/myapp.jar` uses the configuration file name
...
@@ -838,11 +838,11 @@ For example, a jar named `/var/myapp/myapp.jar` uses the configuration file name
TIP: If you do not like having the config file next to the jar file, you can set a `CONF_FOLDER` environment variable to customize the location of the config file.
TIP: If you do not like having the config file next to the jar file, you can set a `CONF_FOLDER` environment variable to customize the location of the config file.
To learn about securing this file appropriately, see <<deployment-initd-service-securing,the guidelines for securing an init.d service>>.
To learn about securing this file appropriately, see <<deployment.installing.nix-services.init-d.securing,the guidelines for securing an init.d service>>.
[[deployment-windows]]
[[deployment.installing.windows-services]]
=== Microsoft Windows Services
=== Microsoft Windows Services
A Spring Boot application can be started as a Windows service by using https://github.com/kohsuke/winsw[`winsw`].
A Spring Boot application can be started as a Windows service by using https://github.com/kohsuke/winsw[`winsw`].
...
@@ -850,7 +850,7 @@ A (https://github.com/snicoll/spring-boot-daemon[separately maintained sample])
...
@@ -850,7 +850,7 @@ A (https://github.com/snicoll/spring-boot-daemon[separately maintained sample])
[[deployment-whats-next]]
[[deployment.whats-next]]
== What to Read Next
== What to Read Next
Check out the https://www.cloudfoundry.org/[Cloud Foundry], https://www.heroku.com/[Heroku], https://www.openshift.com[OpenShift], and https://boxfuse.com[Boxfuse] web sites for more information about the kinds of features that a PaaS can offer.
Check out the https://www.cloudfoundry.org/[Cloud Foundry], https://www.heroku.com/[Heroku], https://www.openshift.com[OpenShift], and https://boxfuse.com[Boxfuse] web sites for more information about the kinds of features that a PaaS can offer.
These are just four of the most popular Java PaaS providers.
These are just four of the most popular Java PaaS providers.
* *Tutorial:* <<getting-started.adoc#getting-started-first-application, Part 1>> | <<getting-started.adoc#getting-started-first-application-code, Part 2>>
* *Tutorial:* <<getting-started.adoc#getting-started.first-application, Part 1>> | <<getting-started.adoc#getting-started.first-application.code, Part 2>>
* *Running your example:* <<getting-started.adoc#getting-started-first-application-run, Part 1>> | <<getting-started.adoc#getting-started-first-application-executable-jar, Part 2>>
* *Running your example:* <<getting-started.adoc#getting-started.first-application.run, Part 1>> | <<getting-started.adoc#getting-started.first-application.executable-jar, Part 2>>
[[boot-documentation-workingwith]]
[[documentation.using]]
== Working with Spring Boot
== Working with Spring Boot
Ready to actually start using Spring Boot? <<using-spring-boot.adoc#using-boot, We have you covered>>:
Ready to actually start using Spring Boot? <<using-spring-boot.adoc#using, We have you covered>>:
When you are ready to push your Spring Boot application to production, we have <<production-ready-features.adoc#production-ready, some tricks>> that you might like:
When you are ready to push your Spring Boot application to production, we have <<production-ready-features.adoc#actuator, some tricks>> that you might like:
Spring Boot supports the following embedded servlet containers:
Spring Boot supports the following embedded servlet containers:
...
@@ -70,7 +70,7 @@ You can also deploy Spring Boot applications to any Servlet 3.1+ compatible cont
...
@@ -70,7 +70,7 @@ You can also deploy Spring Boot applications to any Servlet 3.1+ compatible cont
[[getting-started-installing-spring-boot]]
[[getting-started.installing]]
== Installing Spring Boot
== Installing Spring Boot
Spring Boot can be used with "`classic`" Java development tools or installed as a command line tool.
Spring Boot can be used with "`classic`" Java development tools or installed as a command line tool.
Either way, you need https://www.java.com[Java SDK v1.8] or higher.
Either way, you need https://www.java.com[Java SDK v1.8] or higher.
...
@@ -81,12 +81,12 @@ Before you begin, you should check your current Java installation by using the f
...
@@ -81,12 +81,12 @@ Before you begin, you should check your current Java installation by using the f
$ java -version
$ java -version
----
----
If you are new to Java development or if you want to experiment with Spring Boot, you might want to try the <<getting-started-installing-the-cli, Spring Boot CLI>> (Command Line Interface) first.
If you are new to Java development or if you want to experiment with Spring Boot, you might want to try the <<getting-started.installing.cli, Spring Boot CLI>> (Command Line Interface) first.
Otherwise, read on for "`classic`" installation instructions.
Otherwise, read on for "`classic`" installation instructions.
=== Installation Instructions for the Java Developer
=== Installation Instructions for the Java Developer
You can use Spring Boot in the same way as any standard Java library.
You can use Spring Boot in the same way as any standard Java library.
To do so, include the appropriate `+spring-boot-*.jar+` files on your classpath.
To do so, include the appropriate `+spring-boot-*.jar+` files on your classpath.
...
@@ -97,7 +97,7 @@ Although you _could_ copy Spring Boot jars, we generally recommend that you use
...
@@ -97,7 +97,7 @@ Although you _could_ copy Spring Boot jars, we generally recommend that you use
[[getting-started-maven-installation]]
[[getting-started.installing.java.maven]]
==== Maven Installation
==== Maven Installation
Spring Boot is compatible with Apache Maven 3.3 or above.
Spring Boot is compatible with Apache Maven 3.3 or above.
If you do not already have Maven installed, you can follow the instructions at https://maven.apache.org.
If you do not already have Maven installed, you can follow the instructions at https://maven.apache.org.
...
@@ -108,21 +108,21 @@ Ubuntu users can run `sudo apt-get install maven`.
...
@@ -108,21 +108,21 @@ Ubuntu users can run `sudo apt-get install maven`.
Windows users with https://chocolatey.org/[Chocolatey] can run `choco install maven` from an elevated (administrator) prompt.
Windows users with https://chocolatey.org/[Chocolatey] can run `choco install maven` from an elevated (administrator) prompt.
Spring Boot dependencies use the `org.springframework.boot` `groupId`.
Spring Boot dependencies use the `org.springframework.boot` `groupId`.
Typically, your Maven POM file inherits from the `spring-boot-starter-parent` project and declares dependencies to one or more <<using-spring-boot.adoc#using-boot-starter,"`Starters`">>.
Typically, your Maven POM file inherits from the `spring-boot-starter-parent` project and declares dependencies to one or more <<using-spring-boot.adoc#using.build-systems.starters,"`Starters`">>.
Spring Boot also provides an optional <<build-tool-plugins.adoc#build-tool-plugins-maven-plugin, Maven plugin>> to create executable jars.
Spring Boot also provides an optional <<build-tool-plugins.adoc#build-tool-plugins.maven, Maven plugin>> to create executable jars.
More details on getting started with Spring Boot and Maven can be found in the {spring-boot-maven-plugin-docs}#getting-started[Getting Started section] of the Maven plugin's reference guide.
More details on getting started with Spring Boot and Maven can be found in the {spring-boot-maven-plugin-docs}#getting-started[Getting Started section] of the Maven plugin's reference guide.
[[getting-started-gradle-installation]]
[[getting-started.installing.java.gradle]]
==== Gradle Installation
==== Gradle Installation
Spring Boot is compatible with Gradle 6.8 and 7.x.
Spring Boot is compatible with Gradle 6.8 and 7.x.
If you do not already have Gradle installed, you can follow the instructions at https://gradle.org.
If you do not already have Gradle installed, you can follow the instructions at https://gradle.org.
Spring Boot dependencies can be declared by using the `org.springframework.boot` `group`.
Spring Boot dependencies can be declared by using the `org.springframework.boot` `group`.
Typically, your project declares dependencies to one or more <<using-spring-boot.adoc#using-boot-starter, "`Starters`">>.
Typically, your project declares dependencies to one or more <<using-spring-boot.adoc#using.build-systems.starters, "`Starters`">>.
Spring Boot provides a useful <<build-tool-plugins.adoc#build-tool-plugins-gradle-plugin, Gradle plugin>> that can be used to simplify dependency declarations and to create executable jars.
Spring Boot provides a useful <<build-tool-plugins.adoc#build-tool-plugins.gradle, Gradle plugin>> that can be used to simplify dependency declarations and to create executable jars.
.Gradle Wrapper
.Gradle Wrapper
****
****
...
@@ -135,7 +135,7 @@ More details on getting started with Spring Boot and Gradle can be found in the
...
@@ -135,7 +135,7 @@ More details on getting started with Spring Boot and Gradle can be found in the
[[getting-started-installing-the-cli]]
[[getting-started.installing.cli]]
=== Installing the Spring Boot CLI
=== Installing the Spring Boot CLI
The Spring Boot CLI (Command Line Interface) is a command line tool that you can use to quickly prototype with Spring.
The Spring Boot CLI (Command Line Interface) is a command line tool that you can use to quickly prototype with Spring.
It lets you run https://groovy-lang.org/[Groovy] scripts, which means that you have a familiar Java-like syntax without so much boilerplate code.
It lets you run https://groovy-lang.org/[Groovy] scripts, which means that you have a familiar Java-like syntax without so much boilerplate code.
...
@@ -144,7 +144,7 @@ You do not need to use the CLI to work with Spring Boot, but it is definitely th
...
@@ -144,7 +144,7 @@ You do not need to use the CLI to work with Spring Boot, but it is definitely th
You can download the Spring CLI distribution from the Spring software repository:
You can download the Spring CLI distribution from the Spring software repository:
...
@@ -160,7 +160,7 @@ Alternatively, you can use `java -jar` with the `.jar` file (the script helps yo
...
@@ -160,7 +160,7 @@ Alternatively, you can use `java -jar` with the `.jar` file (the script helps yo
[[getting-started-sdkman-cli-installation]]
[[getting-started.installing.cli.sdkman]]
==== Installation with SDKMAN!
==== Installation with SDKMAN!
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:
...
@@ -206,7 +206,7 @@ You can see it by running the following command:
...
@@ -206,7 +206,7 @@ You can see it by running the following command:
[[getting-started-homebrew-cli-installation]]
[[getting-started.installing.cli.homebrew]]
==== OSX Homebrew Installation
==== OSX Homebrew Installation
If you are on a Mac and use https://brew.sh/[Homebrew], you can install the Spring Boot CLI by using the following commands:
If you are on a Mac and use https://brew.sh/[Homebrew], you can install the Spring Boot CLI by using the following commands:
...
@@ -223,7 +223,7 @@ In that case, run `brew update` and try again.
...
@@ -223,7 +223,7 @@ In that case, run `brew update` and try again.
[[getting-started-macports-cli-installation]]
[[getting-started.installing.cli.macports]]
==== MacPorts Installation
==== MacPorts Installation
If you are on a Mac and use https://www.macports.org/[MacPorts], you can install the Spring Boot CLI by using the following command:
If you are on a Mac and use https://www.macports.org/[MacPorts], you can install the Spring Boot CLI by using the following command:
...
@@ -234,7 +234,7 @@ If you are on a Mac and use https://www.macports.org/[MacPorts], you can install
...
@@ -234,7 +234,7 @@ If you are on a Mac and use https://www.macports.org/[MacPorts], you can install
[[getting-started-cli-command-line-completion]]
[[getting-started.installing.cli.completion]]
==== Command-line Completion
==== Command-line Completion
The Spring Boot CLI includes scripts that provide command completion for the https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29[BASH] and https://en.wikipedia.org/wiki/Z_shell[zsh] shells.
The Spring Boot CLI includes scripts that provide command completion for the https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29[BASH] and https://en.wikipedia.org/wiki/Z_shell[zsh] shells.
You can `source` the script (also named `spring`) in any shell or put it in your personal or system-wide bash completion initialization.
You can `source` the script (also named `spring`) in any shell or put it in your personal or system-wide bash completion initialization.
...
@@ -252,7 +252,7 @@ NOTE: If you install the Spring Boot CLI by using Homebrew or MacPorts, the comm
...
@@ -252,7 +252,7 @@ NOTE: If you install the Spring Boot CLI by using Homebrew or MacPorts, the comm
[[getting-started-scoop-cli-installation]]
[[getting-started.installing.scoop]]
==== Windows Scoop Installation
==== Windows Scoop Installation
If you are on a Windows and use https://scoop.sh/[Scoop], you can install the Spring Boot CLI by using the following commands:
If you are on a Windows and use https://scoop.sh/[Scoop], you can install the Spring Boot CLI by using the following commands:
...
@@ -269,7 +269,7 @@ In that case, run `scoop update` and try again.
...
@@ -269,7 +269,7 @@ In that case, run `scoop update` and try again.
[[getting-started-cli-example]]
[[getting-started.installing.quick-start]]
==== Quick-start Spring CLI Example
==== Quick-start Spring CLI Example
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:
...
@@ -307,7 +307,7 @@ You should see the following output:
...
@@ -307,7 +307,7 @@ You should see the following output:
=== Upgrading from an Earlier Version of Spring Boot
=== Upgrading from an Earlier Version of Spring Boot
If you are upgrading from the `1.x` release of Spring Boot, check the {github-wiki}/Spring-Boot-2.0-Migration-Guide["`migration guide`" on the project wiki] that provides detailed upgrade instructions.
If you are upgrading from the `1.x` release of Spring Boot, check the {github-wiki}/Spring-Boot-2.0-Migration-Guide["`migration guide`" on the project wiki] that provides detailed upgrade instructions.
Check also the {github-wiki}["`release notes`"] for a list of "`new and noteworthy`" features for each release.
Check also the {github-wiki}["`release notes`"] for a list of "`new and noteworthy`" features for each release.
...
@@ -330,11 +330,11 @@ WARNING: Properties that are added late to the environment, such as when using `
...
@@ -330,11 +330,11 @@ WARNING: Properties that are added late to the environment, such as when using `
NOTE: Once you're done with the migration, please make sure to remove this module from your project's dependencies.
NOTE: Once you're done with the migration, please make sure to remove this module from your project's dependencies.
To upgrade an existing CLI installation, use the appropriate package manager command (for example, `brew upgrade`).
To upgrade an existing CLI installation, use the appropriate package manager command (for example, `brew upgrade`).
If you manually installed the CLI, follow the <<getting-started-manual-cli-installation, standard instructions>>, remembering to update your `PATH` environment variable to remove any older references.
If you manually installed the CLI, follow the <<getting-started.installing.cli.manual-installation, standard instructions>>, remembering to update your `PATH` environment variable to remove any older references.
[[getting-started-first-application]]
[[getting-started.first-application]]
== Developing Your First Spring Boot Application
== Developing Your First Spring Boot Application
This section describes how to develop a small "`Hello World!`" web application that highlights some of Spring Boot's key features.
This section describes how to develop a small "`Hello World!`" web application that highlights some of Spring Boot's key features.
We use Maven to build this project, since most IDEs support it.
We use Maven to build this project, since most IDEs support it.
...
@@ -345,7 +345,7 @@ The https://spring.io[spring.io] web site contains many "`Getting Started`" http
...
@@ -345,7 +345,7 @@ The https://spring.io[spring.io] web site contains many "`Getting Started`" http
If you need to solve a specific problem, check there first.
If you need to solve a specific problem, check there first.
You can shortcut the steps below by going to https://start.spring.io and choosing the "Web" starter from the dependencies searcher.
You can shortcut the steps below by going to https://start.spring.io and choosing the "Web" starter from the dependencies searcher.
Doing so generates a new project structure so that you can <<getting-started-first-application-code,start coding right away>>.
Doing so generates a new project structure so that you can <<getting-started.first-application.code,start coding right away>>.
Check the https://github.com/spring-io/start.spring.io/blob/main/USING.adoc[start.spring.io user guide] for more details.
Check the https://github.com/spring-io/start.spring.io/blob/main/USING.adoc[start.spring.io user guide] for more details.
====
====
...
@@ -372,7 +372,7 @@ Subsequent instructions assume that you have created a suitable directory and th
...
@@ -372,7 +372,7 @@ Subsequent instructions assume that you have created a suitable directory and th
[[getting-started-first-application-pom]]
[[getting-started.first-application.pom]]
=== Creating the POM
=== Creating the POM
We need to start by creating a Maven `pom.xml` file.
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.
...
@@ -444,12 +444,12 @@ For simplicity, we continue to use a plain text editor for this example.
...
@@ -444,12 +444,12 @@ For simplicity, we continue to use a plain text editor for this example.
Spring Boot provides a number of "`Starters`" that let you add jars to your classpath.
Spring Boot provides a number of "`Starters`" that let you add jars to your classpath.
Our applications for smoke tests use the `spring-boot-starter-parent` in the `parent` section of the POM.
Our applications for smoke tests use the `spring-boot-starter-parent` in the `parent` section of the POM.
The `spring-boot-starter-parent` is a special starter that provides useful Maven defaults.
The `spring-boot-starter-parent` is a special starter that provides useful Maven defaults.
It also provides a <<using-spring-boot.adoc#using-boot-dependency-management,`dependency-management`>> section so that you can omit `version` tags for "`blessed`" dependencies.
It also provides a <<using-spring-boot.adoc#using.build-systems.dependency-management,`dependency-management`>> section so that you can omit `version` tags for "`blessed`" dependencies.
Other "`Starters`" provide dependencies that you are likely to need when developing a specific type of application.
Other "`Starters`" provide dependencies that you are likely to need when developing a specific type of application.
Since we are developing a web application, we add a `spring-boot-starter-web` dependency.
Since we are developing a web application, we add a `spring-boot-starter-web` dependency.
...
@@ -480,7 +480,7 @@ If you run `mvn dependency:tree` again, you see that there are now a number of a
...
@@ -480,7 +480,7 @@ If you run `mvn dependency:tree` again, you see that there are now a number of a
[[getting-started-first-application-code]]
[[getting-started.first-application.code]]
=== Writing the Code
=== Writing the Code
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/Example.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/Example.java` to contain the following code:
...
@@ -512,7 +512,7 @@ We step through the important parts in the next few sections.
...
@@ -512,7 +512,7 @@ We step through the important parts in the next few sections.
We finish our example by creating a completely self-contained executable jar file that we could run in production.
We finish our example by creating a completely self-contained executable jar file that we could run in production.
Executable jars (sometimes called "`fat jars`") are archives containing your compiled classes along with all of the jar dependencies that your code needs to run.
Executable jars (sometimes called "`fat jars`") are archives containing your compiled classes along with all of the jar dependencies that your code needs to run.
...
@@ -682,11 +682,11 @@ As before, to exit the application, press `ctrl-c`.
...
@@ -682,11 +682,11 @@ As before, to exit the application, press `ctrl-c`.
[[getting-started-whats-next]]
[[getting-started.whats=next]]
== What to Read Next
== What to Read Next
Hopefully, this section provided some of the Spring Boot basics and got you on your way to writing your own applications.
Hopefully, this section provided some of the Spring Boot basics and got you on your way to writing your own applications.
If you are a task-oriented type of developer, you might want to jump over to https://spring.io and check out some of the https://spring.io/guides/[getting started] guides that solve specific "`How do I do that with Spring?`" problems.
If you are a task-oriented type of developer, you might want to jump over to https://spring.io and check out some of the https://spring.io/guides/[getting started] guides that solve specific "`How do I do that with Spring?`" problems.
We also have Spring Boot-specific "`<<howto.adoc#howto, How-to>>`" reference documentation.
We also have Spring Boot-specific "`<<howto.adoc#howto, How-to>>`" reference documentation.
Otherwise, the next logical step is to read _<<using-spring-boot.adoc#using-boot>>_.
Otherwise, the next logical step is to read _<<using-spring-boot.adoc#using>>_.
If you are really impatient, you could also jump ahead and read about _<<spring-boot-features.adoc#boot-features, Spring Boot features>>_.
If you are really impatient, you could also jump ahead and read about _<<spring-boot-features.adoc#features, Spring Boot features>>_.
@@ -13,13 +13,13 @@ If you want to add a '`how-to`', send us a {spring-boot-code}[pull request].
...
@@ -13,13 +13,13 @@ If you want to add a '`how-to`', send us a {spring-boot-code}[pull request].
[[howto-spring-boot-application]]
[[howto.application]]
== Spring Boot Application
== Spring Boot Application
This section includes topics relating directly to Spring Boot applications.
This section includes topics relating directly to Spring Boot applications.
[[howto-failure-analyzer]]
[[howto.application.failure-analyzer]]
=== Create Your Own FailureAnalyzer
=== Create Your Own FailureAnalyzer
{spring-boot-module-api}/diagnostics/FailureAnalyzer.html[`FailureAnalyzer`] is a great way to intercept an exception on startup and turn it into a human-readable message, wrapped in a {spring-boot-module-api}/diagnostics/FailureAnalysis.html[`FailureAnalysis`].
{spring-boot-module-api}/diagnostics/FailureAnalyzer.html[`FailureAnalyzer`] is a great way to intercept an exception on startup and turn it into a human-readable message, wrapped in a {spring-boot-module-api}/diagnostics/FailureAnalysis.html[`FailureAnalysis`].
Spring Boot provides such an analyzer for application-context-related exceptions, JSR-303 validations, and more.
Spring Boot provides such an analyzer for application-context-related exceptions, JSR-303 validations, and more.
...
@@ -42,13 +42,13 @@ NOTE: If you need access to the `BeanFactory` or the `Environment`, your `Failur
...
@@ -42,13 +42,13 @@ NOTE: If you need access to the `BeanFactory` or the `Environment`, your `Failur
The Spring Boot auto-configuration tries its best to "`do the right thing`", but sometimes things fail, and it can be hard to tell why.
The Spring Boot auto-configuration tries its best to "`do the right thing`", but sometimes things fail, and it can be hard to tell why.
There is a really useful `ConditionEvaluationReport` available in any Spring Boot `ApplicationContext`.
There is a really useful `ConditionEvaluationReport` available in any Spring Boot `ApplicationContext`.
You can see it if you enable `DEBUG` logging output.
You can see it if you enable `DEBUG` logging output.
If you use the `spring-boot-actuator` (see <<production-ready-features.adoc#production-ready,the Actuator chapter>>), there is also a `conditions` endpoint that renders the report in JSON.
If you use the `spring-boot-actuator` (see <<production-ready-features.adoc#actuator,the Actuator chapter>>), there is also a `conditions` endpoint that renders the report in JSON.
Use that endpoint to debug the application and see what features have been added (and which have not been added) by Spring Boot at runtime.
Use that endpoint to debug the application and see what features have been added (and which have not been added) by Spring Boot at runtime.
Many more questions can be answered by looking at the source code and the Javadoc.
Many more questions can be answered by looking at the source code and the Javadoc.
...
@@ -69,7 +69,7 @@ When reading the code, remember the following rules of thumb:
...
@@ -69,7 +69,7 @@ When reading the code, remember the following rules of thumb:
=== Customize the Environment or ApplicationContext Before It Starts
=== Customize the Environment or ApplicationContext Before It Starts
A `SpringApplication` has `ApplicationListeners` and `ApplicationContextInitializers` that are used to apply customizations to the context or environment.
A `SpringApplication` has `ApplicationListeners` and `ApplicationContextInitializers` that are used to apply customizations to the context or environment.
Spring Boot loads a number of such customizations for use internally from `META-INF/spring.factories`.
Spring Boot loads a number of such customizations for use internally from `META-INF/spring.factories`.
...
@@ -80,7 +80,7 @@ There is more than one way to register additional customizations:
...
@@ -80,7 +80,7 @@ There is more than one way to register additional customizations:
* Declaratively, for all applications, by adding a `META-INF/spring.factories` and packaging a jar file that the applications all use as a library.
* Declaratively, for all applications, by adding a `META-INF/spring.factories` and packaging a jar file that the applications all use as a library.
The `SpringApplication` sends some special `ApplicationEvents` to the listeners (some even before the context is created) and then registers the listeners for events published by the `ApplicationContext` as well.
The `SpringApplication` sends some special `ApplicationEvents` to the listeners (some even before the context is created) and then registers the listeners for events published by the `ApplicationContext` as well.
See "`<<spring-boot-features.adoc#boot-features-application-events-and-listeners,Application Events and Listeners>>`" in the '`Spring Boot features`' section for a complete list.
See "`<<spring-boot-features.adoc#features.spring-application.application-events-and-listeners,Application Events and Listeners>>`" in the '`Spring Boot features`' section for a complete list.
It is also possible to customize the `Environment` before the application context is refreshed by using `EnvironmentPostProcessor`.
It is also possible to customize the `Environment` before the application context is refreshed by using `EnvironmentPostProcessor`.
Each implementation should be registered in `META-INF/spring.factories`, as shown in the following example:
Each implementation should be registered in `META-INF/spring.factories`, as shown in the following example:
...
@@ -109,14 +109,14 @@ This is too late to configure certain properties such as `+logging.*+` and `+spr
...
@@ -109,14 +109,14 @@ This is too late to configure certain properties such as `+logging.*+` and `+spr
[[howto-build-an-application-context-hierarchy]]
[[howto.application.context-hierarchy]]
=== Build an ApplicationContext Hierarchy (Adding a Parent or Root Context)
=== Build an ApplicationContext Hierarchy (Adding a Parent or Root Context)
You can use the `ApplicationBuilder` class to create parent/child `ApplicationContext` hierarchies.
You can use the `ApplicationBuilder` class to create parent/child `ApplicationContext` hierarchies.
See "`<<spring-boot-features.adoc#boot-features-fluent-builder-api>>`" in the '`Spring Boot features`' section for more information.
See "`<<spring-boot-features.adoc#features.spring-application.fluent-builder-api>>`" in the '`Spring Boot features`' section for more information.
[[howto-create-a-non-web-application]]
[[howto.application.non-web-application]]
=== Create a Non-web Application
=== Create a Non-web Application
Not all Spring applications have to be web applications (or web services).
Not all Spring applications have to be web applications (or web services).
If you want to execute some code in a `main` method but also bootstrap a Spring application to set up the infrastructure to use, you can use the `SpringApplication` features of Spring Boot.
If you want to execute some code in a `main` method but also bootstrap a Spring application to set up the infrastructure to use, you can use the `SpringApplication` features of Spring Boot.
...
@@ -127,20 +127,20 @@ Application code that you want to run as your business logic can be implemented
...
@@ -127,20 +127,20 @@ Application code that you want to run as your business logic can be implemented
[[howto-properties-and-configuration]]
[[howto.properties-and-configuration]]
== Properties and Configuration
== Properties and Configuration
This section includes topics about setting and reading properties and configuration settings and their interaction with Spring Boot applications.
This section includes topics about setting and reading properties and configuration settings and their interaction with Spring Boot applications.
Rather than hardcoding some properties that are also specified in your project's build configuration, you can automatically expand them by instead using the existing build configuration.
Rather than hardcoding some properties that are also specified in your project's build configuration, you can automatically expand them by instead using the existing build configuration.
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:
...
@@ -194,7 +194,7 @@ If that property is not set to `false`, these may be expanded by the build.
...
@@ -194,7 +194,7 @@ If that property is not set to `false`, these may be expanded by the build.
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:
...
@@ -220,7 +220,7 @@ To use Spring property placeholders together with automatic expansion, escape th
...
@@ -220,7 +220,7 @@ To use Spring property placeholders together with automatic expansion, escape th
=== Change the Location of External Properties of an Application
=== Change the Location of External Properties of an Application
By default, properties from different sources are added to the Spring `Environment` in a defined order (see "`<<spring-boot-features.adoc#boot-features-external-config>>`" in the '`Spring Boot features`' section for the exact order).
By default, properties from different sources are added to the Spring `Environment` in a defined order (see "`<<spring-boot-features.adoc#features.external-config>>`" in the '`Spring Boot features`' section for the exact order).
You can also provide the following System properties (or environment variables) to change the behavior:
You can also provide the following System properties (or environment variables) to change the behavior:
...
@@ -280,7 +280,7 @@ See {spring-boot-module-code}/context/config/ConfigFileApplicationListener.java[
...
@@ -280,7 +280,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:
...
@@ -299,7 +299,7 @@ In those two platforms, the `PORT` environment variable is set automatically and
...
@@ -299,7 +299,7 @@ In those two platforms, the `PORT` environment variable is set automatically and
[[howto-use-yaml-for-external-properties]]
[[howto.properties-and-configuration.yaml]]
=== 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:
...
@@ -329,11 +329,11 @@ The preceding example YAML corresponds to the following `application.properties`
...
@@ -329,11 +329,11 @@ The preceding example YAML corresponds to the following `application.properties`
server.port=9000
server.port=9000
----
----
See "`<<spring-boot-features.adoc#boot-features-external-config-yaml>>`" in the '`Spring Boot features`' section for more information about YAML.
See "`<<spring-boot-features.adoc#features.external-config.yaml>>`" in the '`Spring Boot features`' section for more information about YAML.
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:
...
@@ -355,13 +355,13 @@ In Spring Boot, you can also set the active profile in `application.properties`,
...
@@ -355,13 +355,13 @@ In Spring Boot, you can also set the active profile in `application.properties`,
A value set this way is replaced by the System property or environment variable setting but not by the `SpringApplicationBuilder.profiles()` method.
A value set this way is replaced by the System property or environment variable setting but not by the `SpringApplicationBuilder.profiles()` method.
Thus, the latter Java API can be used to augment the profiles without changing the defaults.
Thus, the latter Java API can be used to augment the profiles without changing the defaults.
See "`<<spring-boot-features.adoc#boot-features-profiles>>`" in the "`Spring Boot features`" section for more information.
See "`<<spring-boot-features.adoc#features.profiles>>`" in the "`Spring Boot features`" section for more information.
=== Change Configuration Depending on the Environment
=== Change Configuration Depending on the Environment
Spring Boot supports multi-document YAML and Properties files (see <<spring-boot-features#boot-features-external-config-files-multi-document>> for details) which can be activated conditionally based on the active profiles.
Spring Boot supports multi-document YAML and Properties files (see <<spring-boot-features#features.external-config.files.multi-document>> for details) which can be activated conditionally based on the active profiles.
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:
...
@@ -395,7 +395,7 @@ Later values override earlier values.
...
@@ -395,7 +395,7 @@ Later values override earlier values.
=== Discover Built-in Options for External Properties
=== Discover Built-in Options for External Properties
Spring Boot binds external properties from `application.properties` (or `.yml` files and other places) into an application at runtime.
Spring Boot binds external properties from `application.properties` (or `.yml` files and other places) into an application at runtime.
There is not (and technically cannot be) an exhaustive list of all supported properties in a single location, because contributions can come from additional jar files on your classpath.
There is not (and technically cannot be) an exhaustive list of all supported properties in a single location, because contributions can come from additional jar files on your classpath.
...
@@ -404,11 +404,11 @@ A running application with the Actuator features has a `configprops` endpoint th
...
@@ -404,11 +404,11 @@ A running application with the Actuator features has a `configprops` endpoint th
The appendix includes an <<appendix-application-properties.adoc#common-application-properties, `application.properties`>> example with a list of the most common properties supported by Spring Boot.
The appendix includes an <<appendix-application-properties.adoc#common-application-properties, `application.properties`>> example with a list of the most common properties supported by Spring Boot.
The definitive list comes from searching the source code for `@ConfigurationProperties` and `@Value` annotations as well as the occasional use of `Binder`.
The definitive list comes from searching the source code for `@ConfigurationProperties` and `@Value` annotations as well as the occasional use of `Binder`.
For more about the exact ordering of loading properties, see "<<spring-boot-features#boot-features-external-config>>".
For more about the exact ordering of loading properties, see "<<spring-boot-features#features.external-config>>".
[[howto-embedded-web-servers]]
[[howto.webserver]]
== Embedded Web Servers
== Embedded Web Servers
Each Spring Boot web application includes an embedded web server.
Each Spring Boot web application includes an embedded web server.
This feature leads to a number of how-to questions, including how to change the embedded server and how to configure the embedded server.
This feature leads to a number of how-to questions, including how to change the embedded server and how to configure the embedded server.
...
@@ -416,7 +416,7 @@ This section answers those questions.
...
@@ -416,7 +416,7 @@ This section answers those questions.
[[howto-use-another-web-server]]
[[howto.webserver.use-another]]
=== Use Another Web Server
=== Use Another Web Server
Many Spring Boot starters include default embedded containers.
Many Spring Boot starters include default embedded containers.
...
@@ -476,7 +476,7 @@ NOTE: `spring-boot-starter-reactor-netty` is required to use the `WebClient` cla
...
@@ -476,7 +476,7 @@ NOTE: `spring-boot-starter-reactor-netty` is required to use the `WebClient` cla
[[howto-disable-web-server]]
[[howto.webserver.disable]]
=== Disabling the Web Server
=== Disabling the Web Server
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:
...
@@ -490,24 +490,24 @@ To disable this behavior configure the `WebApplicationType` in your `application
...
@@ -490,24 +490,24 @@ To disable this behavior configure the `WebApplicationType` in your `application
[[howto-change-the-http-port]]
[[howto.webserver.change-port]]
=== Change the HTTP Port
=== Change the HTTP Port
In a standalone application, the main HTTP port defaults to `8080` but can be set with configprop:server.port[] (for example, in `application.properties` or as a System property).
In a standalone application, the main HTTP port defaults to `8080` but can be set with configprop:server.port[] (for example, in `application.properties` or as a System property).
Thanks to relaxed binding of `Environment` values, you can also use configprop:server.port[format=envvar] (for example, as an OS environment variable).
Thanks to relaxed binding of `Environment` values, you can also use configprop:server.port[format=envvar] (for example, as an OS environment variable).
To switch off the HTTP endpoints completely but still create a `WebApplicationContext`, use `server.port=-1` (doing so is sometimes useful for testing).
To switch off the HTTP endpoints completely but still create a `WebApplicationContext`, use `server.port=-1` (doing so is sometimes useful for testing).
For more details, see "`<<spring-boot-features.adoc#boot-features-customizing-embedded-containers>>`" in the '`Spring Boot Features`' section, or the {spring-boot-autoconfigure-module-code}/web/ServerProperties.java[`ServerProperties`] source code.
For more details, see "`<<spring-boot-features.adoc#features.developing-web-applications.embedded-container.customizing>>`" in the '`Spring Boot Features`' section, or the {spring-boot-autoconfigure-module-code}/web/ServerProperties.java[`ServerProperties`] source code.
[[howto-user-a-random-unassigned-http-port]]
[[howto.webserver.use-random-port]]
=== Use a Random Unassigned HTTP Port
=== Use a Random Unassigned HTTP Port
To scan for a free port (using OS natives to prevent clashes) use `server.port=0`.
To scan for a free port (using OS natives to prevent clashes) use `server.port=0`.
[[howto-discover-the-http-port-at-runtime]]
[[howto.webserver.discover-port]]
=== Discover the HTTP Port at Runtime
=== Discover the HTTP Port at Runtime
You can access the port the server is running on from log output or from the `WebServerApplicationContext` through its `WebServer`.
You can access the port the server is running on from log output or from the `WebServerApplicationContext` through its `WebServer`.
The best way to get that and be sure it has been initialized is to add a `@Bean` of type `ApplicationListener<WebServerInitializedEvent>` and pull the container out of the event when it is published.
The best way to get that and be sure it has been initialized is to add a `@Bean` of type `ApplicationListener<WebServerInitializedEvent>` and pull the container out of the event when it is published.
...
@@ -537,7 +537,7 @@ Contrary to a test, application code callbacks are processed early (before the v
...
@@ -537,7 +537,7 @@ Contrary to a test, application code callbacks are processed early (before the v
[[how-to-enable-http-response-compression]]
[[howto.webserver.enable-response-compression]]
=== Enable HTTP Response Compression
=== Enable HTTP Response Compression
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:
...
@@ -567,7 +567,7 @@ You can configure this behavior by setting the configprop:server.compression.mim
...
@@ -567,7 +567,7 @@ You can configure this behavior by setting the configprop:server.compression.mim
[[howto-configure-ssl]]
[[howto.webserver.configure-ssl]]
=== Configure SSL
=== Configure SSL
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`:
...
@@ -591,7 +591,7 @@ We recommend using `application.properties` to configure HTTPS, as the HTTP conn
...
@@ -591,7 +591,7 @@ We recommend using `application.properties` to configure HTTPS, as the HTTP conn
[[howto-configure-http2]]
[[howto.webserver.configure-http2]]
=== Configure HTTP/2
=== Configure HTTP/2
You can enable HTTP/2 support in your Spring Boot application with the configprop:server.http2.enabled[] configuration property.
You can enable HTTP/2 support in your Spring Boot application with the configprop:server.http2.enabled[] configuration property.
Both `h2` (HTTP/2 over TLS) and `h2c` (HTTP/2 over TCP) are supported.
Both `h2` (HTTP/2 over TLS) and `h2c` (HTTP/2 over TCP) are supported.
...
@@ -601,7 +601,7 @@ The details of the `h2` support depend on the chosen web server and the applicat
...
@@ -601,7 +601,7 @@ The details of the `h2` support depend on the chosen web server and the applicat
[[howto-configure-http2-tomcat]]
[[howto.webserver.configure-http2.tomcat]]
==== HTTP/2 with Tomcat
==== HTTP/2 with Tomcat
Spring Boot ships by default with Tomcat 9.0.x which supports `h2c` out of the box and `h2` out of the box when using JDK 9 or later.
Spring Boot ships by default with Tomcat 9.0.x which supports `h2c` out of the box and `h2` out of the box when using JDK 9 or later.
Alternatively, `h2` can be used on JDK 8 if the `libtcnative` library and its dependencies are installed on the host operating system.
Alternatively, `h2` can be used on JDK 8 if the `libtcnative` library and its dependencies are installed on the host operating system.
...
@@ -621,7 +621,7 @@ This error is not fatal, and the application still starts with HTTP/1.1 SSL supp
...
@@ -621,7 +621,7 @@ This error is not fatal, and the application still starts with HTTP/1.1 SSL supp
[[howto-configure-http2-jetty]]
[[howto.webserver.configure-http2.jetty]]
==== HTTP/2 with Jetty
==== HTTP/2 with Jetty
For HTTP/2 support, Jetty requires the additional `org.eclipse.jetty.http2:http2-server` dependency.
For HTTP/2 support, Jetty requires the additional `org.eclipse.jetty.http2:http2-server` dependency.
To use `h2c` no other dependencies are required.
To use `h2c` no other dependencies are required.
...
@@ -633,7 +633,7 @@ To use `h2`, you also need to choose one of the following dependencies, dependin
...
@@ -633,7 +633,7 @@ To use `h2`, you also need to choose one of the following dependencies, dependin
[[howto-configure-http2-netty]]
[[howto.webserver.configure-http2.netty]]
==== HTTP/2 with Reactor Netty
==== HTTP/2 with Reactor Netty
The `spring-boot-webflux-starter` is using by default Reactor Netty as a server.
The `spring-boot-webflux-starter` is using by default Reactor Netty as a server.
Reactor Netty supports `h2c` using JDK 8 or later with no additional dependencies.
Reactor Netty supports `h2c` using JDK 8 or later with no additional dependencies.
...
@@ -646,15 +646,15 @@ Developers can choose to import only the required dependencies using a classifie
...
@@ -646,15 +646,15 @@ Developers can choose to import only the required dependencies using a classifie
[[howto-configure-http2-undertow]]
[[howto.webserver.configure-http2.undertow]]
==== HTTP/2 with Undertow
==== HTTP/2 with Undertow
As of Undertow 1.4.0+, both `h2` and `h2c` are supported on JDK 8 without any additional dependencies.
As of Undertow 1.4.0+, both `h2` and `h2c` are supported on JDK 8 without any additional dependencies.
[[howto-configure-webserver]]
[[howto.webserver.configure]]
=== Configure the Web Server
=== Configure the Web Server
Generally, you should first consider using one of the many available configuration keys and customize your web server by adding new entries in your `application.properties` (or `application.yml`, or environment, etc. see "`<<howto-discover-build-in-options-for-external-properties>>`").
Generally, you should first consider using one of the many available configuration keys and customize your web server by adding new entries in your `application.properties` (or `application.yml`, or environment, etc. see "`<<howto.properties-and-configuration.discover-build-in-options-for-external-properties>>`").
The `server.{asterisk}` namespace is quite useful here, and it includes namespaces like `server.tomcat.{asterisk}`, `server.jetty.{asterisk}` and others, for server-specific features.
The `server.{asterisk}` namespace is quite useful here, and it includes namespaces like `server.tomcat.{asterisk}`, `server.jetty.{asterisk}` and others, for server-specific features.
See the list of <<appendix-application-properties.adoc#common-application-properties>>.
See the list of <<appendix-application-properties.adoc#common-application-properties>>.
...
@@ -711,16 +711,16 @@ When you do so, auto-configured customizers are still applied on your custom fac
...
@@ -711,16 +711,16 @@ When you do so, auto-configured customizers are still applied on your custom fac
[[howto-add-a-servlet-filter-or-listener]]
[[howto.webserver.add-servlet-filter-listener]]
=== Add a Servlet, Filter, or Listener to an Application
=== Add a Servlet, Filter, or Listener to an Application
In a servlet stack application, i.e. with the `spring-boot-starter-web`, there are two ways to add `Servlet`, `Filter`, `ServletContextListener`, and the other listeners supported by the Servlet API to your application:
In a servlet stack application, i.e. with the `spring-boot-starter-web`, there are two ways to add `Servlet`, `Filter`, `ServletContextListener`, and the other listeners supported by the Servlet API to your application:
==== Add a Servlet, Filter, or Listener by Using a Spring Bean
==== Add a Servlet, Filter, or Listener by Using a Spring Bean
To add a `Servlet`, `Filter`, or Servlet `*Listener` by using a Spring bean, you must provide a `@Bean` definition for it.
To add a `Servlet`, `Filter`, or Servlet `*Listener` by using a Spring bean, you must provide a `@Bean` definition for it.
Doing so can be very useful when you want to inject configuration or dependencies.
Doing so can be very useful when you want to inject configuration or dependencies.
...
@@ -736,13 +736,13 @@ If no `dispatcherType` is specified on a filter registration, `REQUEST` is used.
...
@@ -736,13 +736,13 @@ If no `dispatcherType` is specified on a filter registration, `REQUEST` is used.
This aligns with the Servlet Specification's default dispatcher type.
This aligns with the Servlet Specification's default dispatcher type.
====
====
Like any other Spring bean, you can define the order of Servlet filter beans; please make sure to check the "`<<spring-boot-features.adoc#boot-features-embedded-container-servlets-filters-listeners-beans>>`" section.
Like any other Spring bean, you can define the order of Servlet filter beans; please make sure to check the "`<<spring-boot-features.adoc#features.developing-web-applications.embedded-container.servlets-filters-listeners.beans>>`" section.
As <<howto-add-a-servlet-filter-or-listener-as-spring-bean,described earlier>>, any `Servlet` or `Filter` beans are registered with the servlet container automatically.
As <<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:
==== Add Servlets, Filters, and Listeners by Using Classpath Scanning
==== Add Servlets, Filters, and Listeners by Using Classpath Scanning
`@WebServlet`, `@WebFilter`, and `@WebListener` annotated classes can be automatically registered with an embedded servlet container by annotating a `@Configuration` class with `@ServletComponentScan` and specifying the package(s) containing the components that you want to register.
`@WebServlet`, `@WebFilter`, and `@WebListener` annotated classes can be automatically registered with an embedded servlet container by annotating a `@Configuration` class with `@ServletComponentScan` and specifying the package(s) containing the components that you want to register.
By default, `@ServletComponentScan` scans from the package of the annotated class.
By default, `@ServletComponentScan` scans from the package of the annotated class.
[[howto-configure-accesslogs]]
[[howto.webserver.configure-access-logs]]
=== Configure Access Logging
=== Configure Access Logging
Access logs can be configured for Tomcat, Undertow, and Jetty through their respective namespaces.
Access logs can be configured for Tomcat, Undertow, and Jetty through their respective namespaces.
...
@@ -814,7 +814,7 @@ For more details, see the Jetty documentation.
...
@@ -814,7 +814,7 @@ For more details, see the Jetty documentation.
[[howto-use-behind-a-proxy-server]]
[[howto.webserver.use-behind-a-proxy-server]]
=== Running Behind a Front-end Proxy Server
=== Running Behind a Front-end Proxy Server
If your application is running behind a proxy, a load-balancer or in the cloud, the request information (like the host, port, scheme...) might change along the way.
If your application is running behind a proxy, a load-balancer or in the cloud, the request information (like the host, port, scheme...) might change along the way.
Your application may be running on `10.10.10.10:8080`, but HTTP clients should only see `example.org`.
Your application may be running on `10.10.10.10:8080`, but HTTP clients should only see `example.org`.
...
@@ -837,7 +837,7 @@ In all other instances, it defaults to `NONE`.
...
@@ -837,7 +837,7 @@ In all other instances, it defaults to `NONE`.
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:
=== 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:
...
@@ -943,7 +943,7 @@ When deployed to a standalone servlet container, this role is performed by a ser
...
@@ -943,7 +943,7 @@ When deployed to a standalone servlet container, this role is performed by a ser
[[howto-spring-mvc]]
[[howto.spring-mvc]]
== Spring MVC
== Spring MVC
Spring Boot has a number of starters that include Spring MVC.
Spring Boot has a number of starters that include Spring MVC.
Note that some starters include a dependency on Spring MVC rather than include it directly.
Note that some starters include a dependency on Spring MVC rather than include it directly.
...
@@ -951,7 +951,7 @@ This section answers common questions about Spring MVC and Spring Boot.
...
@@ -951,7 +951,7 @@ This section answers common questions about Spring MVC and Spring Boot.
[[howto-write-a-json-rest-service]]
[[howto.spring-mvc.write-json-rest-service]]
=== 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:
...
@@ -973,7 +973,7 @@ Note that, in a browser, you might sometimes see XML responses, because browsers
...
@@ -973,7 +973,7 @@ Note that, in a browser, you might sometimes see XML responses, because browsers
[[howto-write-an-xml-rest-service]]
[[howto.spring-mvc.write-xml-rest-service]]
=== Write an XML REST Service
=== Write an XML REST Service
If you have the Jackson XML extension (`jackson-dataformat-xml`) on the classpath, you can use it to render XML responses.
If you have the Jackson XML extension (`jackson-dataformat-xml`) on the classpath, you can use it to render XML responses.
The previous example that we used for JSON would work.
The previous example that we used for JSON would work.
...
@@ -1013,7 +1013,7 @@ NOTE: To get the server to render XML instead of JSON, you might have to send an
...
@@ -1013,7 +1013,7 @@ NOTE: To get the server to render XML instead of JSON, you might have to send an
Spring MVC (client and server side) uses `HttpMessageConverters` to negotiate content conversion in an HTTP exchange.
Spring MVC (client and server side) uses `HttpMessageConverters` to negotiate content conversion in an HTTP exchange.
If Jackson is on the classpath, you already get the default converter(s) provided by `Jackson2ObjectMapperBuilder`, an instance of which is auto-configured for you.
If Jackson is on the classpath, you already get the default converter(s) provided by `Jackson2ObjectMapperBuilder`, an instance of which is auto-configured for you.
...
@@ -1059,7 +1059,7 @@ These features are described in six enums (in Jackson) that map onto properties
...
@@ -1059,7 +1059,7 @@ These features are described in six enums (in Jackson) that map onto properties
|===
|===
For example, to enable pretty print, set `spring.jackson.serialization.indent_output=true`.
For example, to enable pretty print, set `spring.jackson.serialization.indent_output=true`.
Note that, thanks to the use of <<spring-boot-features.adoc#boot-features-external-config-relaxed-binding, relaxed binding>>, the case of `indent_output` does not have to match the case of the corresponding enum constant, which is `INDENT_OUTPUT`.
Note that, thanks to the use of <<spring-boot-features.adoc#features.external-config.typesafe-configuration-properties.relaxed-binding, relaxed binding>>, the case of `indent_output` does not have to match the case of the corresponding enum constant, which is `INDENT_OUTPUT`.
This environment-based configuration is applied to the auto-configured `Jackson2ObjectMapperBuilder` bean and applies to any mappers created by using the builder, including the auto-configured `ObjectMapper` bean.
This environment-based configuration is applied to the auto-configured `Jackson2ObjectMapperBuilder` bean and applies to any mappers created by using the builder, including the auto-configured `ObjectMapper` bean.
...
@@ -1076,11 +1076,11 @@ If you provide any `@Beans` of type `MappingJackson2HttpMessageConverter`, they
...
@@ -1076,11 +1076,11 @@ If you provide any `@Beans` of type `MappingJackson2HttpMessageConverter`, they
Also, a convenience bean of type `HttpMessageConverters` is provided (and is always available if you use the default MVC configuration).
Also, a convenience bean of type `HttpMessageConverters` is provided (and is always available if you use the default MVC configuration).
It has some useful methods to access the default and user-enhanced message converters.
It has some useful methods to access the default and user-enhanced message converters.
See the "`<<howto-customize-the-responsebody-rendering>>`" section and the {spring-boot-autoconfigure-module-code}/web/servlet/WebMvcAutoConfiguration.java[`WebMvcAutoConfiguration`] source code for more details.
See the "`<<howtospring-mvc.customize-responsebody-rendering>>`" section and the {spring-boot-autoconfigure-module-code}/web/servlet/WebMvcAutoConfiguration.java[`WebMvcAutoConfiguration`] source code for more details.
The easiest way to take complete control over MVC configuration is to provide your own `@Configuration` with the `@EnableWebMvc` annotation.
The easiest way to take complete control over MVC configuration is to provide your own `@Configuration` with the `@EnableWebMvc` annotation.
Doing so leaves all MVC configuration in your hands.
Doing so leaves all MVC configuration in your hands.
[[howto-customize-view-resolvers]]
[[howto.spring-mvc.customize-view-resolvers]]
=== Customize ViewResolvers
=== Customize ViewResolvers
A `ViewResolver` is a core component of Spring MVC, translating view names in `@Controller` to actual `View` implementations.
A `ViewResolver` is a core component of Spring MVC, translating view names in `@Controller` to actual `View` implementations.
Note that `ViewResolvers` are mainly used in UI applications, rather than REST-style services (a `View` is not used to render a `@ResponseBody`).
Note that `ViewResolvers` are mainly used in UI applications, rather than REST-style services (a `View` is not used to render a `@ResponseBody`).
...
@@ -1189,7 +1189,7 @@ For more detail, see the following sections:
...
@@ -1189,7 +1189,7 @@ For more detail, see the following sections:
[[howto-use-test-with-spring-security]]
[[howto.testing-with-spring-security]]
== Testing With Spring Security
== Testing With Spring Security
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.
...
@@ -1211,12 +1211,12 @@ For additional details on Spring Security's testing support, refer to Spring Sec
...
@@ -1211,12 +1211,12 @@ For additional details on Spring Security's testing support, refer to Spring Sec
[[howto-jersey]]
[[howto.jersey]]
== Jersey
== Jersey
[[howto-jersey-spring-security]]
[[howto.jersey.spring-security]]
=== Secure Jersey endpoints with Spring Security
=== Secure Jersey endpoints with Spring Security
Spring Security can be used to secure a Jersey-based web application in much the same way as it can be used to secure a Spring MVC-based web application.
Spring Security can be used to secure a Jersey-based web application in much the same way as it can be used to secure a Spring MVC-based web application.
However, if you want to use Spring Security's method-level security with Jersey, you must configure Jersey to use `setStatus(int)` rather `sendError(int)`.
However, if you want to use Spring Security's method-level security with Jersey, you must configure Jersey to use `setStatus(int)` rather `sendError(int)`.
To use Jersey alongside another web framework, such as Spring MVC, it should be configured so that it will allow the other framework to handle requests that it cannot handle.
To use Jersey alongside another web framework, such as Spring MVC, it should be configured so that it will allow the other framework to handle requests that it cannot handle.
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`.
...
@@ -1252,16 +1252,16 @@ Second, configure your `ResourceConfig` to forward requests that would have resu
...
@@ -1252,16 +1252,16 @@ Second, configure your `ResourceConfig` to forward requests that would have resu
[[howto-http-clients]]
[[howto.http-clients]]
== HTTP Clients
== HTTP Clients
Spring Boot offers a number of starters that work with HTTP clients.
Spring Boot offers a number of starters that work with HTTP clients.
This section answers questions related to using them.
This section answers questions related to using them.
As described in <<spring-boot-features.adoc#boot-features-resttemplate-customization>>, you can use a `RestTemplateCustomizer` with `RestTemplateBuilder` to build a customized `RestTemplate`.
As described in <<spring-boot-features.adoc#features.resttemplate.customization>>, you can use a `RestTemplateCustomizer` with `RestTemplateBuilder` to build a customized `RestTemplate`.
This is the recommended approach for creating a `RestTemplate` configured to use a proxy.
This is the recommended approach for creating a `RestTemplate` configured to use a proxy.
The exact details of the proxy configuration depend on the underlying client request factory that is being used.
The exact details of the proxy configuration depend on the underlying client request factory that is being used.
=== Configure the TcpClient used by a Reactor Netty-based WebClient
=== Configure the TcpClient used by a Reactor Netty-based WebClient
When Reactor Netty is on the classpath a Reactor Netty-based `WebClient` is auto-configured.
When Reactor Netty is on the classpath a Reactor Netty-based `WebClient` is auto-configured.
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.
...
@@ -1290,7 +1290,7 @@ This ensures efficient sharing of resources for the server receiving requests an
...
@@ -1290,7 +1290,7 @@ This ensures efficient sharing of resources for the server receiving requests an
[[howto-logging]]
[[howto.logging]]
== Logging
== Logging
Spring Boot has no mandatory logging dependency, except for the Commons Logging API, which is typically provided by Spring Framework's `spring-jcl` module.
Spring Boot has no mandatory logging dependency, except for the Commons Logging API, which is typically provided by Spring Framework's `spring-jcl` module.
To use https://logback.qos.ch[Logback], you need to include it and `spring-jcl` on the classpath.
To use https://logback.qos.ch[Logback], you need to include it and `spring-jcl` on the classpath.
...
@@ -1326,11 +1326,11 @@ By default, Spring Boot picks up the native configuration from its default locat
...
@@ -1326,11 +1326,11 @@ By default, Spring Boot picks up the native configuration from its default locat
[[howto-configure-logback-for-logging]]
[[howto.logging.logback]]
=== Configure Logback for Logging
=== Configure Logback for Logging
If you need to apply customizations to logback beyond those that can be achieved with `application.properties`, you'll need to add a standard logback configuration file.
If you need to apply customizations to logback beyond those that can be achieved with `application.properties`, you'll need to add a standard logback configuration file.
You can add a `logback.xml` file to the root of your classpath for logback to find.
You can add a `logback.xml` file to the root of your classpath for logback to find.
You can also use `logback-spring.xml` if you want to use the <<spring-boot-features.adoc#boot-features-logback-extensions,Spring Boot Logback extensions>>.
You can also use `logback-spring.xml` if you want to use the <<spring-boot-features.adoc#features.logging.logback-extensions,Spring Boot Logback extensions>>.
TIP: The Logback documentation has a https://logback.qos.ch/manual/configuration.html[dedicated section that covers configuration] in some detail.
TIP: The Logback documentation has a https://logback.qos.ch/manual/configuration.html[dedicated section that covers configuration] in some detail.
...
@@ -1379,7 +1379,7 @@ Any `logback-spring.groovy` files will not be detected.
...
@@ -1379,7 +1379,7 @@ Any `logback-spring.groovy` files will not be detected.
[[howto-configure-logback-for-logging-fileonly]]
[[howto.logging.logback.file-only-output]]
==== 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:
...
@@ -1407,7 +1407,7 @@ You also need to add `logging.file.name` to your `application.properties` or `ap
...
@@ -1407,7 +1407,7 @@ You also need to add `logging.file.name` to your `application.properties` or `ap
[[howto-configure-log4j-for-logging]]
[[howto.logging.log4j]]
=== Configure Log4j for Logging
=== Configure Log4j for Logging
Spring Boot supports https://logging.apache.org/log4j/2.x/[Log4j 2] for logging configuration if it is on the classpath.
Spring Boot supports https://logging.apache.org/log4j/2.x/[Log4j 2] for logging configuration if it is on the classpath.
If you use the starters for assembling dependencies, you have to exclude Logback and then include log4j 2 instead.
If you use the starters for assembling dependencies, you have to exclude Logback and then include log4j 2 instead.
...
@@ -1462,7 +1462,7 @@ NOTE: To ensure that debug logging performed using `java.util.logging` is routed
...
@@ -1462,7 +1462,7 @@ NOTE: To ensure that debug logging performed using `java.util.logging` is routed
In addition to its default XML configuration format, Log4j 2 also supports YAML and JSON configuration files.
In addition to its default XML configuration format, Log4j 2 also supports YAML and JSON configuration files.
To configure Log4j 2 to use an alternative configuration file format, add the appropriate dependencies to the classpath and name your configuration files to match your chosen file format, as shown in the following example:
To configure Log4j 2 to use an alternative configuration file format, add the appropriate dependencies to the classpath and name your configuration files to match your chosen file format, as shown in the following example:
...
@@ -1482,18 +1482,18 @@ To configure Log4j 2 to use an alternative configuration file format, add the ap
...
@@ -1482,18 +1482,18 @@ To configure Log4j 2 to use an alternative configuration file format, add the ap
[[howto-data-access]]
[[howto.data-access]]
== Data Access
== Data Access
Spring Boot includes a number of starters for working with data sources.
Spring Boot includes a number of starters for working with data sources.
This section answers questions related to doing so.
This section answers questions related to doing so.
[[howto-configure-a-datasource]]
[[howto.data-access.configure-custom-datasource]]
=== Configure a Custom DataSource
=== Configure a Custom DataSource
To configure your own `DataSource`, define a `@Bean` of that type in your configuration.
To configure your own `DataSource`, define a `@Bean` of that type in your configuration.
Spring Boot reuses your `DataSource` anywhere one is required, including database initialization.
Spring Boot reuses your `DataSource` anywhere one is required, including database initialization.
If you need to externalize some settings, you can bind your `DataSource` to the environment (see "`<<spring-boot-features.adoc#boot-features-external-config-3rd-party-configuration>>`").
If you need to externalize some settings, you can bind your `DataSource` to the environment (see "`<<spring-boot-features.adoc#features.external-config.typesafe-configuration-properties.3rd-party-configuration>>`").
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:
...
@@ -1601,11 +1601,11 @@ This example uses a more generic `configuration` sub namespace as the example do
...
@@ -1601,11 +1601,11 @@ This example uses a more generic `configuration` sub namespace as the example do
NOTE: Because your custom configuration chooses to go with Hikari, `app.datasource.type` has no effect.
NOTE: Because your custom configuration chooses to go with Hikari, `app.datasource.type` has no effect.
In practice, the builder is initialized with whatever value you might set there and then overridden by the call to `.type()`.
In practice, the builder is initialized with whatever value you might set there and then overridden by the call to `.type()`.
See "`<<spring-boot-features.adoc#boot-features-configure-datasource>>`" in the "`Spring Boot features`" section and the {spring-boot-autoconfigure-module-code}/jdbc/DataSourceAutoConfiguration.java[`DataSourceAutoConfiguration`] class for more details.
See "`<<spring-boot-features.adoc#features.sql.datasource>>`" in the "`Spring Boot features`" section and the {spring-boot-autoconfigure-module-code}/jdbc/DataSourceAutoConfiguration.java[`DataSourceAutoConfiguration`] class for more details.
[[howto-two-datasources]]
[[howto.data-access.configure-two-datasources]]
=== Configure Two DataSources
=== Configure Two DataSources
If you need to configure multiple data sources, you can apply the same tricks that are described in the previous section.
If you need to configure multiple data sources, you can apply the same tricks that are described in the previous section.
You must, however, mark one of the `DataSource` instances as `@Primary`, because various auto-configurations down the road expect to be able to get one by type.
You must, however, mark one of the `DataSource` instances as `@Primary`, because various auto-configurations down the road expect to be able to get one by type.
...
@@ -1653,7 +1653,7 @@ Note that each `configuration` sub namespace provides advanced settings based on
...
@@ -1653,7 +1653,7 @@ Note that each `configuration` sub namespace provides advanced settings based on
[[howto-use-spring-data-repositories]]
[[howto.data-access.spring-data-repositories]]
=== Use Spring Data Repositories
=== Use Spring Data Repositories
Spring Data can create implementations of `@Repository` interfaces of various flavors.
Spring Data can create implementations of `@Repository` interfaces of various flavors.
Spring Boot handles all of that for you, as long as those `@Repositories` are included in the same package (or a sub-package) of your `@EnableAutoConfiguration` class.
Spring Boot handles all of that for you, as long as those `@Repositories` are included in the same package (or a sub-package) of your `@EnableAutoConfiguration` class.
...
@@ -1669,7 +1669,7 @@ For more about Spring Data, see the {spring-data}[Spring Data project page].
...
@@ -1669,7 +1669,7 @@ For more about Spring Data, see the {spring-data}[Spring Data project page].
=== Separate @Entity Definitions from Spring Configuration
=== Separate @Entity Definitions from Spring Configuration
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:
...
@@ -1688,7 +1688,7 @@ To get more control, you can use the `@EntityScan` annotation, as shown in the f
...
@@ -1688,7 +1688,7 @@ To get more control, you can use the `@EntityScan` annotation, as shown in the f
[[howto-configure-jpa-properties]]
[[howto.data-access.jpa-properties]]
=== Configure JPA Properties
=== Configure JPA Properties
Spring Data JPA already provides some vendor-independent configuration options (such as those for SQL logging), and Spring Boot exposes those options and a few more for Hibernate as external configuration properties.
Spring Data JPA already provides some vendor-independent configuration options (such as those for SQL logging), and Spring Boot exposes those options and a few more for Hibernate as external configuration properties.
Some of them are automatically detected according to the context so you should not have to set them.
Some of them are automatically detected according to the context so you should not have to set them.
...
@@ -1728,7 +1728,7 @@ This takes precedence to anything that is applied by the auto-configuration.
...
@@ -1728,7 +1728,7 @@ This takes precedence to anything that is applied by the auto-configuration.
Hibernate uses {hibernate-docs}#naming[two different naming strategies] to map names from the object model to the corresponding database names.
Hibernate uses {hibernate-docs}#naming[two different naming strategies] to map names from the object model to the corresponding database names.
The fully qualified class name of the physical and the implicit strategy implementations can be configured by setting the `spring.jpa.hibernate.naming.physical-strategy` and `spring.jpa.hibernate.naming.implicit-strategy` properties, respectively.
The fully qualified class name of the physical and the implicit strategy implementations can be configured by setting the `spring.jpa.hibernate.naming.physical-strategy` and `spring.jpa.hibernate.naming.implicit-strategy` properties, respectively.
...
@@ -1763,7 +1763,7 @@ See {spring-boot-autoconfigure-module-code}/orm/jpa/HibernateJpaAutoConfiguratio
...
@@ -1763,7 +1763,7 @@ See {spring-boot-autoconfigure-module-code}/orm/jpa/HibernateJpaAutoConfiguratio
Hibernate {hibernate-docs}#caching[second-level cache] can be configured for a range of cache providers.
Hibernate {hibernate-docs}#caching[second-level cache] can be configured for a range of cache providers.
Rather than configuring Hibernate to lookup the cache provider again, it is better to provide the one that is available in the context whenever possible.
Rather than configuring Hibernate to lookup the cache provider again, it is better to provide the one that is available in the context whenever possible.
...
@@ -1782,7 +1782,7 @@ For details, refer to {hibernate-docs}#caching-provider-jcache[the Hibernate use
...
@@ -1782,7 +1782,7 @@ For details, refer to {hibernate-docs}#caching-provider-jcache[the Hibernate use
=== Use Dependency Injection in Hibernate Components
=== Use Dependency Injection in Hibernate Components
By default, Spring Boot registers a `BeanContainer` implementation that uses the `BeanFactory` so that converters and entity listeners can use regular dependency injection.
By default, Spring Boot registers a `BeanContainer` implementation that uses the `BeanFactory` so that converters and entity listeners can use regular dependency injection.
...
@@ -1790,15 +1790,15 @@ You can disable or tune this behaviour by registering a `HibernatePropertiesCust
...
@@ -1790,15 +1790,15 @@ You can disable or tune this behaviour by registering a `HibernatePropertiesCust
[[howto-use-custom-entity-manager]]
[[howto.data-access.use-custom-entity-manager]]
=== Use a Custom EntityManagerFactory
=== Use a Custom EntityManagerFactory
To take full control of the configuration of the `EntityManagerFactory`, you need to add a `@Bean` named '`entityManagerFactory`'.
To take full control of the configuration of the `EntityManagerFactory`, you need to add a `@Bean` named '`entityManagerFactory`'.
Spring Boot auto-configuration switches off its entity manager in the presence of a bean of that type.
Spring Boot auto-configuration switches off its entity manager in the presence of a bean of that type.
Spring Boot will not search for or use a `META-INF/persistence.xml` by default.
Spring Boot will not search for or use a `META-INF/persistence.xml` by default.
If you prefer to use a traditional `persistence.xml`, you need to define your own `@Bean` of type `LocalEntityManagerFactoryBean` (with an ID of '`entityManagerFactory`') and set the persistence unit name there.
If you prefer to use a traditional `persistence.xml`, you need to define your own `@Bean` of type `LocalEntityManagerFactoryBean` (with an ID of '`entityManagerFactory`') and set the persistence unit name there.
...
@@ -1851,7 +1851,7 @@ See {spring-boot-autoconfigure-module-code}/orm/jpa/JpaBaseConfiguration.java[`J
...
@@ -1851,7 +1851,7 @@ See {spring-boot-autoconfigure-module-code}/orm/jpa/JpaBaseConfiguration.java[`J
If you need to use jOOQ with multiple data sources, you should create your own `DSLContext` for each one.
If you need to use jOOQ with multiple data sources, you should create your own `DSLContext` for each one.
Refer to {spring-boot-autoconfigure-module-code}/jooq/JooqAutoConfiguration.java[JooqAutoConfiguration] for more details.
Refer to {spring-boot-autoconfigure-module-code}/jooq/JooqAutoConfiguration.java[JooqAutoConfiguration] for more details.
...
@@ -1911,7 +1911,7 @@ TIP: In particular, `JooqExceptionTranslator` and `SpringTransactionProvider` ca
...
@@ -1911,7 +1911,7 @@ TIP: In particular, `JooqExceptionTranslator` and `SpringTransactionProvider` ca
[[howto-database-initialization]]
[[howto.data-initialization]]
== Database Initialization
== Database Initialization
An SQL database can be initialized in different ways depending on what your stack is.
An SQL database can be initialized in different ways depending on what your stack is.
Of course, you can also do it manually, provided the database is a separate process.
Of course, you can also do it manually, provided the database is a separate process.
...
@@ -1919,7 +1919,7 @@ It is recommended to use a single mechanism for schema generation.
...
@@ -1919,7 +1919,7 @@ It is recommended to use a single mechanism for schema generation.
[[howto-initialize-a-database-using-jpa]]
[[howto.data-initialization.using-jpa]]
=== Initialize a Database Using JPA
=== Initialize a Database Using JPA
JPA has features for DDL generation, and these can be set up to run on startup against the database.
JPA has features for DDL generation, and these can be set up to run on startup against the database.
This is controlled through two external properties:
This is controlled through two external properties:
...
@@ -1930,7 +1930,7 @@ This is controlled through two external properties:
...
@@ -1930,7 +1930,7 @@ This is controlled through two external properties:
[[howto-initialize-a-database-using-hibernate]]
[[howto.data-initialization.using-hibernate]]
=== Initialize a Database Using Hibernate
=== Initialize a Database Using Hibernate
You can set `spring.jpa.hibernate.ddl-auto` explicitly and the standard Hibernate property values are `none`, `validate`, `update`, `create`, and `create-drop`.
You can set `spring.jpa.hibernate.ddl-auto` explicitly and the standard Hibernate property values are `none`, `validate`, `update`, `create`, and `create-drop`.
Spring Boot chooses a default value for you based on whether it thinks your database is embedded.
Spring Boot chooses a default value for you based on whether it thinks your database is embedded.
...
@@ -1941,7 +1941,7 @@ Be careful when switching from in-memory to a '`real`' database that you do not
...
@@ -1941,7 +1941,7 @@ Be careful when switching from in-memory to a '`real`' database that you do not
You either have to set `ddl-auto` explicitly or use one of the other mechanisms to initialize the database.
You either have to set `ddl-auto` explicitly or use one of the other mechanisms to initialize the database.
NOTE: You can output the schema creation by enabling the `org.hibernate.SQL` logger.
NOTE: You can output the schema creation by enabling the `org.hibernate.SQL` logger.
This is done for you automatically if you enable the <<spring-boot-features.adoc#boot-features-logging-console-output,debug mode>>.
This is done for you automatically if you enable the <<spring-boot-features.adoc#features.logging.console-output,debug mode>>.
In addition, a file named `import.sql` in the root of the classpath is executed on startup if Hibernate creates the schema from scratch (that is, if the `ddl-auto` property is set to `create` or `create-drop`).
In addition, a file named `import.sql` in the root of the classpath is executed on startup if Hibernate creates the schema from scratch (that is, if the `ddl-auto` property is set to `create` or `create-drop`).
This can be useful for demos and for testing if you are careful but is probably not something you want to be on the classpath in production.
This can be useful for demos and for testing if you are careful but is probably not something you want to be on the classpath in production.
...
@@ -1949,7 +1949,7 @@ It is a Hibernate feature (and has nothing to do with Spring).
...
@@ -1949,7 +1949,7 @@ It is a Hibernate feature (and has nothing to do with Spring).
Spring Boot can automatically create the schema (DDL scripts) of your JDBC `DataSource` or R2DBC `ConnectionFactory` and initialize it (DML scripts).
Spring Boot can automatically create the schema (DDL scripts) of your JDBC `DataSource` or R2DBC `ConnectionFactory` and initialize it (DML scripts).
It loads SQL from the standard root classpath locations: `schema.sql` and `data.sql`, respectively.
It loads SQL from the standard root classpath locations: `schema.sql` and `data.sql`, respectively.
...
@@ -1967,12 +1967,12 @@ While we do not recommend using multiple data source initialization technologies
...
@@ -1967,12 +1967,12 @@ While we do not recommend using multiple data source initialization technologies
This will defer data source initialization until after any `EntityManagerFactory` beans have been created and initialized.
This will defer data source initialization until after any `EntityManagerFactory` beans have been created and initialized.
`schema.sql` can then be used to make additions to any schema creation performed by Hibernate and `data.sql` can be used to populate it.
`schema.sql` can then be used to make additions to any schema creation performed by Hibernate and `data.sql` can be used to populate it.
If you are using a <<spring-boot-features.adoc#howto-use-a-higher-level-database-migration-tool,Higher-level Database Migration Tool>>, like Flyway or Liquibase, you should use them alone to create and initialize the schema.
If you are using a <<spring-boot-features.adoc#howto.data-initialization.migration-tool,Higher-level Database Migration Tool>>, like Flyway or Liquibase, you should use them alone to create and initialize the schema.
Using the basic `schema.sql` and `data.sql` scripts alongside Flyway or Liquibase is not recommended and support will be removed in a future release.
Using the basic `schema.sql` and `data.sql` scripts alongside Flyway or Liquibase is not recommended and support will be removed in a future release.
[[howto-initialize-a-spring-batch-database]]
[[howto.data-initialization.batch]]
=== Initialize a Spring Batch Database
=== Initialize a Spring Batch Database
If you use Spring Batch, it comes pre-packaged with SQL initialization scripts for most popular database platforms.
If you use Spring Batch, it comes pre-packaged with SQL initialization scripts for most popular database platforms.
Spring Boot can detect your database type and execute those scripts on startup.
Spring Boot can detect your database type and execute those scripts on startup.
...
@@ -1991,13 +1991,13 @@ You can also switch off the initialization explicitly by setting `spring.batch.j
...
@@ -1991,13 +1991,13 @@ You can also switch off the initialization explicitly by setting `spring.batch.j
Database initialization is performed while the application is starting up as part of application context refresh.
Database initialization is performed while the application is starting up as part of application context refresh.
To allow an initialized database to be accessed during startup, beans that act as database initializers and beans that require that database to have been initialized are detected automatically.
To allow an initialized database to be accessed during startup, beans that act as database initializers and beans that require that database to have been initialized are detected automatically.
...
@@ -2099,7 +2099,7 @@ If, during startup, your application tries to access the database and it has not
...
@@ -2099,7 +2099,7 @@ If, during startup, your application tries to access the database and it has not
If your JMS broker does not support transacted sessions, you have to disable the support of transactions altogether.
If your JMS broker does not support transacted sessions, you have to disable the support of transactions altogether.
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.
...
@@ -2163,14 +2163,14 @@ The preceding example overrides the default factory, and it should be applied to
...
@@ -2163,14 +2163,14 @@ The preceding example overrides the default factory, and it should be applied to
[[howto-batch-applications]]
[[howto.batch]]
== Batch Applications
== Batch Applications
A number of questions often arise when people use Spring Batch from within a Spring Boot application.
A number of questions often arise when people use Spring Batch from within a Spring Boot application.
This section addresses those questions.
This section addresses those questions.
[[howto-spring-batch-specifying-a-data-source]]
[[howto.batch.specifying-a-data-source]]
=== Specifying a Batch Data Source
=== Specifying a Batch Data Source
By default, batch applications require a `DataSource` to store job details.
By default, batch applications require a `DataSource` to store job details.
Spring Batch expects a single `DataSource` by default.
Spring Batch expects a single `DataSource` by default.
...
@@ -2183,7 +2183,7 @@ For more info about Spring Batch, see the {spring-batch}[Spring Batch project pa
...
@@ -2183,7 +2183,7 @@ For more info about Spring Batch, see the {spring-batch}[Spring Batch project pa
[[howto-spring-batch-running-jobs-on-startup]]
[[howto.batch.running-jobs-on-startup]]
=== Running Spring Batch Jobs on Startup
=== Running Spring Batch Jobs on Startup
Spring Batch auto-configuration is enabled by adding `@EnableBatchProcessing` to one of your `@Configuration` classes.
Spring Batch auto-configuration is enabled by adding `@EnableBatchProcessing` to one of your `@Configuration` classes.
...
@@ -2194,9 +2194,9 @@ See {spring-boot-autoconfigure-module-code}/batch/BatchAutoConfiguration.java[Ba
...
@@ -2194,9 +2194,9 @@ See {spring-boot-autoconfigure-module-code}/batch/BatchAutoConfiguration.java[Ba
[[howto-spring-batch-running-command-line]]
[[howto.batch.?running-from-the-command-line]]
=== Running from the Command Line
=== Running from the Command Line
Spring Boot converts any command line argument starting with `--` to a property to add to the `Environment`, see <<spring-boot-features.adoc#boot-features-external-config-command-line-args,accessing command line properties>>.
Spring Boot converts any command line argument starting with `--` to a property to add to the `Environment`, see <<spring-boot-features.adoc#features.external-config.command-line-args,accessing command line properties>>.
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:
...
@@ -2217,7 +2217,7 @@ This provides only one argument to the batch job: `someParameter=someValue`.
...
@@ -2217,7 +2217,7 @@ This provides only one argument to the batch job: `someParameter=someValue`.
[[howto-spring-batch-storing-job-repository]]
[[howto.batch.storing-job-repository]]
=== Storing the Job Repository
=== Storing the Job Repository
Spring Batch requires a data store for the `Job` repository.
Spring Batch requires a data store for the `Job` repository.
If you use Spring Boot, you must use an actual database.
If you use Spring Boot, you must use an actual database.
...
@@ -2225,24 +2225,24 @@ Note that it can be an in-memory database, see {spring-batch-docs}job.html#confi
...
@@ -2225,24 +2225,24 @@ Note that it can be an in-memory database, see {spring-batch-docs}job.html#confi
[[howto-actuator]]
[[howto.actuator]]
== Actuator
== Actuator
Spring Boot includes the Spring Boot Actuator.
Spring Boot includes the Spring Boot Actuator.
This section answers questions that often arise from its use.
This section answers questions that often arise from its use.
=== Change the HTTP Port or Address of the Actuator Endpoints
=== Change the HTTP Port or Address of the Actuator Endpoints
In a standalone application, the Actuator HTTP port defaults to the same as the main HTTP port.
In a standalone application, the Actuator HTTP port defaults to the same as the main HTTP port.
To make the application listen on a different port, set the external property: configprop:management.server.port[].
To make the application listen on a different port, set the external property: configprop:management.server.port[].
To listen on a completely different network address (such as when you have an internal network for management and an external one for user applications), you can also set `management.server.address` to a valid IP address to which the server is able to bind.
To listen on a completely different network address (such as when you have an internal network for management and an external one for user applications), you can also set `management.server.address` to a valid IP address to which the server is able to bind.
For more detail, see the {spring-boot-actuator-autoconfigure-module-code}/web/server/ManagementServerProperties.java[`ManagementServerProperties`] source code and "`<<production-ready-features.adoc#production-ready-customizing-management-server-port>>`" in the "`Production-ready features`" section.
For more detail, see the {spring-boot-actuator-autoconfigure-module-code}/web/server/ManagementServerProperties.java[`ManagementServerProperties`] source code and "`<<production-ready-features.adoc#actuator.monitoring.customizing-management-server-port>>`" in the "`Production-ready features`" section.
Spring Boot installs a '`whitelabel`' error page that you see in a browser client if you encounter a server error (machine clients consuming JSON and other media types should see a sensible response with the right error code).
Spring Boot installs a '`whitelabel`' error page that you see in a browser client if you encounter a server error (machine clients consuming JSON and other media types should see a sensible response with the right error code).
...
@@ -2257,12 +2257,12 @@ In general, you need a `View` that resolves with a name of `error` or a `@Contro
...
@@ -2257,12 +2257,12 @@ In general, you need a `View` that resolves with a name of `error` or a `@Contro
Unless you replaced some of the default configuration, you should find a `BeanNameViewResolver` in your `ApplicationContext`, so a `@Bean` named `error` would be one way of doing that.
Unless you replaced some of the default configuration, you should find a `BeanNameViewResolver` in your `ApplicationContext`, so a `@Bean` named `error` would be one way of doing that.
See {spring-boot-autoconfigure-module-code}/web/servlet/error/ErrorMvcAutoConfiguration.java[`ErrorMvcAutoConfiguration`] for more options.
See {spring-boot-autoconfigure-module-code}/web/servlet/error/ErrorMvcAutoConfiguration.java[`ErrorMvcAutoConfiguration`] for more options.
See also the section on "`<<spring-boot-features.adoc#boot-features-error-handling, Error Handling>>`" for details of how to register handlers in the servlet container.
See also the section on "`<<spring-boot-features.adoc#features.developing-web-applications.spring-mvc.error-handling, Error Handling>>`" for details of how to register handlers in the servlet container.
[[howto-sanitize-sensible-values]]
[[howto.actuator.sanitize-sensitive-values]]
[[howto-sanitize-sensitive-values]]
[[howto.actuator.sanitize-sensitive-values]]
=== Sanitize Sensitive Values
=== Sanitize Sensitive Values
Information returned by the `env` and `configprops` endpoints can be somewhat sensitive so keys matching certain patterns are sanitized by default (i.e. their values are replaced by `+******+`). Spring Boot uses sensible defaults for such keys: any key ending with the word "password", "secret", "key", "token", "vcap_services", "sun.java.command" is entirely sanitized.
Information returned by the `env` and `configprops` endpoints can be somewhat sensitive so keys matching certain patterns are sanitized by default (i.e. their values are replaced by `+******+`). Spring Boot uses sensible defaults for such keys: any key ending with the word "password", "secret", "key", "token", "vcap_services", "sun.java.command" is entirely sanitized.
Additionally, any key that holds the word `credentials` (configured as a regular expression, i.e. `+*credentials.*+`) as part of the key is also entirely sanitized.
Additionally, any key that holds the word `credentials` (configured as a regular expression, i.e. `+*credentials.*+`) as part of the key is also entirely sanitized.
...
@@ -2285,7 +2285,7 @@ Alternatively, additional patterns can be configured using configprop:management
...
@@ -2285,7 +2285,7 @@ Alternatively, additional patterns can be configured using configprop:management
This section addresses questions about security when working with Spring Boot, including questions that arise from using Spring Security with Spring Boot.
This section addresses questions about security when working with Spring Boot, including questions that arise from using Spring Security with Spring Boot.
...
@@ -2309,13 +2309,13 @@ For more about Spring Security, see the {spring-security}[Spring Security projec
...
@@ -2309,13 +2309,13 @@ For more about Spring Security, see the {spring-security}[Spring Security projec
=== Switch off the Spring Boot Security Configuration
=== Switch off the Spring Boot Security Configuration
If you define a `@Configuration` with a `WebSecurityConfigurerAdapter` or a `SecurityFilterChain` bean in your application, it switches off the default webapp security settings in Spring Boot.
If you define a `@Configuration` with a `WebSecurityConfigurerAdapter` or a `SecurityFilterChain` bean in your application, it switches off the default webapp security settings in Spring Boot.
=== Change the UserDetailsService and Add User Accounts
=== Change the UserDetailsService and Add User Accounts
If you provide a `@Bean` of type `AuthenticationManager`, `AuthenticationProvider`, or `UserDetailsService`, the default `@Bean` for `InMemoryUserDetailsManager` is not created.
If you provide a `@Bean` of type `AuthenticationManager`, `AuthenticationProvider`, or `UserDetailsService`, the default `@Bean` for `InMemoryUserDetailsManager` is not created.
This means you have the full feature set of Spring Security available (such as {spring-security-docs}#servlet-authentication[various authentication options]).
This means you have the full feature set of Spring Security available (such as {spring-security-docs}#servlet-authentication[various authentication options]).
...
@@ -2324,7 +2324,7 @@ The easiest way to add user accounts is to provide your own `UserDetailsService`
...
@@ -2324,7 +2324,7 @@ The easiest way to add user accounts is to provide your own `UserDetailsService`
[[howto-enable-https]]
[[howto.security.enable-https]]
=== Enable HTTPS When Running behind a Proxy Server
=== Enable HTTPS When Running behind a Proxy Server
Ensuring that all your main endpoints are only available over HTTPS is an important chore for any application.
Ensuring that all your main endpoints are only available over HTTPS is an important chore for any application.
If you use Tomcat as a servlet container, then Spring Boot adds Tomcat's own `RemoteIpValve` automatically if it detects some environment settings, and you should be able to rely on the `HttpServletRequest` to report whether it is secure or not (even downstream of a proxy server that handles the real SSL termination).
If you use Tomcat as a servlet container, then Spring Boot adds Tomcat's own `RemoteIpValve` automatically if it detects some environment settings, and you should be able to rely on the `HttpServletRequest` to report whether it is secure or not (even downstream of a proxy server that handles the real SSL termination).
...
@@ -2357,22 +2357,22 @@ To configure Spring Security to require a secure channel for all (or some) reque
...
@@ -2357,22 +2357,22 @@ To configure Spring Security to require a secure channel for all (or some) reque
[[howto-hotswapping]]
[[howto.hotswapping]]
== Hot Swapping
== Hot Swapping
Spring Boot supports hot swapping.
Spring Boot supports hot swapping.
This section answers questions about how it works.
This section answers questions about how it works.
[[howto-reload-static-content]]
[[howto.hotswapping.reload-static-content]]
=== Reload Static Content
=== Reload Static Content
There are several options for hot reloading.
There are several options for hot reloading.
The recommended approach is to use <<using-spring-boot.adoc#using-boot-devtools,`spring-boot-devtools`>>, as it provides additional development-time features, such as support for fast application restarts and LiveReload as well as sensible development-time configuration (such as template caching).
The recommended approach is to use <<using-spring-boot.adoc#using.devtools,`spring-boot-devtools`>>, as it provides additional development-time features, such as support for fast application restarts and LiveReload as well as sensible development-time configuration (such as template caching).
Devtools works by monitoring the classpath for changes.
Devtools works by monitoring the classpath for changes.
This means that static resource changes must be "built" for the change to take effect.
This means that static resource changes must be "built" for the change to take effect.
By default, this happens automatically in Eclipse when you save your changes.
By default, this happens automatically in Eclipse when you save your changes.
In IntelliJ IDEA, the Make Project command triggers the necessary build.
In IntelliJ IDEA, the Make Project command triggers the necessary build.
Due to the <<using-spring-boot.adoc#using-boot-devtools-restart-exclude, default restart exclusions>>, changes to static resources do not trigger a restart of your application.
Due to the <<using-spring-boot.adoc#using.devtools.restart.excluding-resources, default restart exclusions>>, changes to static resources do not trigger a restart of your application.
They do, however, trigger a live reload.
They do, however, trigger a live reload.
Alternatively, running in an IDE (especially with debugging on) is a good way to do development (all modern IDEs allow reloading of static resources and usually also allow hot-swapping of Java class changes).
Alternatively, running in an IDE (especially with debugging on) is a good way to do development (all modern IDEs allow reloading of static resources and usually also allow hot-swapping of Java class changes).
...
@@ -2382,59 +2382,59 @@ You can use that with an external css/js compiler process if you are writing tha
...
@@ -2382,59 +2382,59 @@ You can use that with an external css/js compiler process if you are writing tha
[[howto-reload-thymeleaf-template-content]]
[[howto.hotswapping.reload-templates]]
=== Reload Templates without Restarting the Container
=== Reload Templates without Restarting the Container
Most of the templating technologies supported by Spring Boot include a configuration option to disable caching (described later in this document).
Most of the templating technologies supported by Spring Boot include a configuration option to disable caching (described later in this document).
If you use the `spring-boot-devtools` module, these properties are <<using-spring-boot.adoc#using-boot-devtools-property-defaults,automatically configured>> for you at development time.
If you use the `spring-boot-devtools` module, these properties are <<using-spring-boot.adoc#using.devtools.property-defaults,automatically configured>> for you at development time.
[[howto-reload-thymeleaf-content]]
[[howto.hotswapping.reload-templates.thymeleaf]]
==== Thymeleaf Templates
==== Thymeleaf Templates
If you use Thymeleaf, set `spring.thymeleaf.cache` to `false`.
If you use Thymeleaf, set `spring.thymeleaf.cache` to `false`.
See {spring-boot-autoconfigure-module-code}/thymeleaf/ThymeleafAutoConfiguration.java[`ThymeleafAutoConfiguration`] for other Thymeleaf customization options.
See {spring-boot-autoconfigure-module-code}/thymeleaf/ThymeleafAutoConfiguration.java[`ThymeleafAutoConfiguration`] for other Thymeleaf customization options.
[[howto-reload-freemarker-content]]
[[howto.hotswapping.reload-templates.freemarker]]
==== FreeMarker Templates
==== FreeMarker Templates
If you use FreeMarker, set `spring.freemarker.cache` to `false`.
If you use FreeMarker, set `spring.freemarker.cache` to `false`.
See {spring-boot-autoconfigure-module-code}/freemarker/FreeMarkerAutoConfiguration.java[`FreeMarkerAutoConfiguration`] for other FreeMarker customization options.
See {spring-boot-autoconfigure-module-code}/freemarker/FreeMarkerAutoConfiguration.java[`FreeMarkerAutoConfiguration`] for other FreeMarker customization options.
[[howto-reload-groovy-template-content]]
[[howto.hotswapping.reload-templates.groovy]]
==== Groovy Templates
==== Groovy Templates
If you use Groovy templates, set `spring.groovy.template.cache` to `false`.
If you use Groovy templates, set `spring.groovy.template.cache` to `false`.
See {spring-boot-autoconfigure-module-code}/groovy/template/GroovyTemplateAutoConfiguration.java[`GroovyTemplateAutoConfiguration`] for other Groovy customization options.
See {spring-boot-autoconfigure-module-code}/groovy/template/GroovyTemplateAutoConfiguration.java[`GroovyTemplateAutoConfiguration`] for other Groovy customization options.
[[howto-reload-fast-restart]]
[[howto.hotswapping.fast-application-restarts]]
=== Fast Application Restarts
=== Fast Application Restarts
The `spring-boot-devtools` module includes support for automatic application restarts.
The `spring-boot-devtools` module includes support for automatic application restarts.
While not as fast as technologies such as https://www.jrebel.com/products/jrebel[JRebel] it is usually significantly faster than a "`cold start`".
While not as fast as technologies such as https://www.jrebel.com/products/jrebel[JRebel] it is usually significantly faster than a "`cold start`".
You should probably give it a try before investigating some of the more complex reload options discussed later in this document.
You should probably give it a try before investigating some of the more complex reload options discussed later in this document.
For more details, see the <<using-spring-boot.adoc#using-boot-devtools>> section.
For more details, see the <<using-spring-boot.adoc#using.devtools>> section.
=== Reload Java Classes without Restarting the Container
=== Reload Java Classes without Restarting the Container
Many modern IDEs (Eclipse, IDEA, and others) support hot swapping of bytecode.
Many modern IDEs (Eclipse, IDEA, and others) support hot swapping of bytecode.
Consequently, if you make a change that does not affect class or method signatures, it should reload cleanly with no side effects.
Consequently, if you make a change that does not affect class or method signatures, it should reload cleanly with no side effects.
[[howto-build]]
[[howto.build]]
== Build
== Build
Spring Boot includes build plugins for Maven and Gradle.
Spring Boot includes build plugins for Maven and Gradle.
This section answers common questions about these plugins.
This section answers common questions about these plugins.
[[howto-build-info]]
[[howto.build.generate-info]]
=== Generate Build Information
=== Generate Build Information
Both the Maven plugin and the Gradle plugin allow generating build information containing the coordinates, name, and version of the project.
Both the Maven plugin and the Gradle plugin allow generating build information containing the coordinates, name, and version of the project.
The plugins can also be configured to add additional properties through configuration.
The plugins can also be configured to add additional properties through configuration.
...
@@ -2477,7 +2477,7 @@ TIP: See the {spring-boot-gradle-plugin-docs}#integrating-with-actuator-build-in
...
@@ -2477,7 +2477,7 @@ TIP: See the {spring-boot-gradle-plugin-docs}#integrating-with-actuator-build-in
[[howto-git-info]]
[[howto.build.generate-git-info]]
=== Generate Git Information
=== Generate Git Information
Both Maven and Gradle allow generating a `git.properties` file containing information about the state of your `git` source code repository when the project was built.
Both Maven and Gradle allow generating a `git.properties` file containing information about the state of your `git` source code repository when the project was built.
...
@@ -2513,7 +2513,7 @@ Using this format lets the time be parsed into a `Date` and its format, when ser
...
@@ -2513,7 +2513,7 @@ Using this format lets the time be parsed into a `Date` and its format, when ser
[[howto-customize-dependency-versions]]
[[howto.build.customize-dependency-versions]]
=== Customize Dependency Versions
=== Customize Dependency Versions
The `spring-boot-dependencies` POM manages the versions of common dependencies.
The `spring-boot-dependencies` POM manages the versions of common dependencies.
The Spring Boot plugins for Maven and Gradle allow these managed dependency versions to be customized using build properties.
The Spring Boot plugins for Maven and Gradle allow these managed dependency versions to be customized using build properties.
...
@@ -2527,7 +2527,7 @@ To override dependency versions in Gradle, see {spring-boot-gradle-plugin-docs}#
...
@@ -2527,7 +2527,7 @@ To override dependency versions in Gradle, see {spring-boot-gradle-plugin-docs}#
Like a war file, a Spring Boot application is not intended to be used as a dependency.
Like a war file, a Spring Boot application is not intended to be used as a dependency.
If your application contains classes that you want to share with other projects, the recommended approach is to move that code into a separate module.
If your application contains classes that you want to share with other projects, the recommended approach is to move that code into a separate module.
The separate module can then be depended upon by your application and other projects.
The separate module can then be depended upon by your application and other projects.
If you cannot rearrange your code as recommended above, Spring Boot's Maven and Gradle plugins must be configured to produce a separate artifact that is suitable for use as a dependency.
If you cannot rearrange your code as recommended above, Spring Boot's Maven and Gradle plugins must be configured to produce a separate artifact that is suitable for use as a dependency.
The executable archive cannot be used as a dependency as the <<appendix-executable-jar-format.adoc#executable-jar-jar-file-structure,executable jar format>> packages application classes in `BOOT-INF/classes`.
The executable archive cannot be used as a dependency as the <<appendix-executable-jar-format.adoc#executable-jar.nested-jars.jar-structure,executable jar format>> packages application classes in `BOOT-INF/classes`.
This means that they cannot be found when the executable jar is used as a dependency.
This means that they cannot be found when the executable jar is used as a dependency.
To produce the two artifacts, one that can be used as a dependency and one that is executable, a classifier must be specified.
To produce the two artifacts, one that can be used as a dependency and one that is executable, a classifier must be specified.
...
@@ -2603,7 +2603,7 @@ To configure a classifier of `exec` in Maven, you can use the following configur
...
@@ -2603,7 +2603,7 @@ To configure a classifier of `exec` in Maven, you can use the following configur
=== Extract Specific Libraries When an Executable Jar Runs
=== Extract Specific Libraries When an Executable Jar Runs
Most nested libraries in an executable jar do not need to be unpacked in order to run.
Most nested libraries in an executable jar do not need to be unpacked in order to run.
However, certain libraries can have problems.
However, certain libraries can have problems.
...
@@ -2638,7 +2638,7 @@ For example, to indicate that JRuby should be flagged for unpacking by using the
...
@@ -2638,7 +2638,7 @@ For example, to indicate that JRuby should be flagged for unpacking by using the
[[howto-create-a-nonexecutable-jar]]
[[howto.build.create-a-nonexecutable-jar]]
=== Create a Non-executable JAR with Exclusions
=== Create a Non-executable JAR with Exclusions
Often, if you have an executable and a non-executable jar as two separate build products, the executable version has additional configuration files that are not needed in a library jar.
Often, if you have an executable and a non-executable jar as two separate build products, the executable version has additional configuration files that are not needed in a library jar.
For example, the `application.yml` configuration file might be excluded from the non-executable JAR.
For example, the `application.yml` configuration file might be excluded from the non-executable JAR.
...
@@ -2677,7 +2677,7 @@ In Maven, the executable jar must be the main artifact and you can add a classif
...
@@ -2677,7 +2677,7 @@ In Maven, the executable jar must be the main artifact and you can add a classif
[[howto-remote-debug-maven-run]]
[[howto.build.remote-debug-maven]]
=== Remote Debug a Spring Boot Application Started with Maven
=== Remote Debug a Spring Boot Application Started with Maven
To attach a remote debugger to a Spring Boot application that was started with Maven, you can use the `jvmArguments` property of the {spring-boot-maven-plugin-docs}[maven plugin].
To attach a remote debugger to a Spring Boot application that was started with Maven, you can use the `jvmArguments` property of the {spring-boot-maven-plugin-docs}[maven plugin].
...
@@ -2685,7 +2685,7 @@ See {spring-boot-maven-plugin-docs}#run-example-debug[this example] for more det
...
@@ -2685,7 +2685,7 @@ See {spring-boot-maven-plugin-docs}#run-example-debug[this example] for more det
=== Build an Executable Archive from Ant without Using spring-boot-antlib
=== Build an Executable Archive from Ant without Using spring-boot-antlib
To build with Ant, you need to grab dependencies, compile, and then create a jar or war archive.
To build with Ant, you need to grab dependencies, compile, and then create a jar or war archive.
To make it executable, you can either use the `spring-boot-antlib` module or you can follow these instructions:
To make it executable, you can either use the `spring-boot-antlib` module or you can follow these instructions:
...
@@ -2728,14 +2728,14 @@ The following example shows how to build an executable archive with Ant:
...
@@ -2728,14 +2728,14 @@ The following example shows how to build an executable archive with Ant:
[[howto-traditional-deployment]]
[[howto.traditional-deployment]]
== Traditional Deployment
== Traditional Deployment
Spring Boot supports traditional deployment as well as more modern forms of deployment.
Spring Boot supports traditional deployment as well as more modern forms of deployment.
This section answers common questions about traditional deployment.
This section answers common questions about traditional deployment.
[[howto-create-a-deployable-war-file]]
[[howto.howto.traditional-deployment.war]]
=== Create a Deployable War File
=== Create a Deployable War File
WARNING: Because Spring WebFlux does not strictly depend on the Servlet API and applications are deployed by default on an embedded Reactor Netty server, War deployment is not supported for WebFlux applications.
WARNING: Because Spring WebFlux does not strictly depend on the Servlet API and applications are deployed by default on an embedded Reactor Netty server, War deployment is not supported for WebFlux applications.
...
@@ -2813,7 +2813,7 @@ This means that, in addition to being deployable to a servlet container, you can
...
@@ -2813,7 +2813,7 @@ This means that, in addition to being deployable to a servlet container, you can
=== Convert an Existing Application to Spring Boot
=== Convert an Existing Application to Spring Boot
To convert an existing non-web Spring application to a Spring Boot application, replace the code that creates your `ApplicationContext` and replace it with calls to `SpringApplication` or `SpringApplicationBuilder`.
To convert an existing non-web Spring application to a Spring Boot application, replace the code that creates your `ApplicationContext` and replace it with calls to `SpringApplication` or `SpringApplicationBuilder`.
Spring MVC web applications are generally amenable to first creating a deployable war application and then migrating it later to an executable war or jar.
Spring MVC web applications are generally amenable to first creating a deployable war application and then migrating it later to an executable war or jar.
...
@@ -2900,7 +2900,7 @@ Servlet 3.0+ applications might translate pretty easily if they already use the
...
@@ -2900,7 +2900,7 @@ Servlet 3.0+ applications might translate pretty easily if they already use the
Normally, all the code from an existing `WebApplicationInitializer` can be moved into a `SpringBootServletInitializer`.
Normally, all the code from an existing `WebApplicationInitializer` can be moved into a `SpringBootServletInitializer`.
If your existing application has more than one `ApplicationContext` (for example, if it uses `AbstractDispatcherServletInitializer`) then you might be able to combine all your context sources into a single `SpringApplication`.
If your existing application has more than one `ApplicationContext` (for example, if it uses `AbstractDispatcherServletInitializer`) then you might be able to combine all your context sources into a single `SpringApplication`.
The main complication you might encounter is if combining does not work and you need to maintain the context hierarchy.
The main complication you might encounter is if combining does not work and you need to maintain the context hierarchy.
See the <<howto-build-an-application-context-hierarchy, entry on building a hierarchy>> for examples.
See the <<howto.application.context-hierarchy, entry on building a hierarchy>> for examples.
An existing parent context that contains web-specific features usually needs to be broken up so that all the `ServletContextAware` components are in the child context.
An existing parent context that contains web-specific features usually needs to be broken up so that all the `ServletContextAware` components are in the child context.
Applications that are not already Spring applications might be convertible to Spring Boot applications, and the previously mentioned guidance may help.
Applications that are not already Spring applications might be convertible to Spring Boot applications, and the previously mentioned guidance may help.
...
@@ -2909,7 +2909,7 @@ In that case, we suggest https://stackoverflow.com/questions/tagged/spring-boot[
...
@@ -2909,7 +2909,7 @@ In that case, we suggest https://stackoverflow.com/questions/tagged/spring-boot[
[[howto-weblogic]]
[[howto.howto.traditional-deployment.weblogic]]
=== Deploying a WAR to WebLogic
=== Deploying a WAR to WebLogic
To deploy a Spring Boot application to WebLogic, you must ensure that your servlet initializer *directly* implements `WebApplicationInitializer` (even if you extend from a base class that already implements it).
To deploy a Spring Boot application to WebLogic, you must ensure that your servlet initializer *directly* implements `WebApplicationInitializer` (even if you extend from a base class that already implements it).
...
@@ -2950,7 +2950,7 @@ You can do so by adding a `WEB-INF/weblogic.xml` file with the following content
...
@@ -2950,7 +2950,7 @@ You can do so by adding a `WEB-INF/weblogic.xml` file with the following content
@@ -10,11 +10,11 @@ The reference documentation consists of the following sections:
...
@@ -10,11 +10,11 @@ The reference documentation consists of the following sections:
[horizontal]
[horizontal]
<<legal.adoc#legal,Legal>> :: Legal information.
<<legal.adoc#legal,Legal>> :: Legal information.
<<documentation-overview.adoc#boot-documentation,Documentation Overview>> :: About the Documentation, Getting Help, First Steps, and more.
<<documentation-overview.adoc#documentation,Documentation Overview>> :: About the Documentation, Getting Help, First Steps, and more.
<<getting-started.adoc#getting-started,Getting Started>> :: Introducing Spring Boot, System Requirements, Servlet Containers, Installing Spring Boot, Developing Your First Spring Boot Application
<<getting-started.adoc#getting-started,Getting Started>> :: Introducing Spring Boot, System Requirements, Servlet Containers, Installing Spring Boot, Developing Your First Spring Boot Application
<<using-spring-boot.adoc#using-boot,Using Spring Boot>> :: Build Systems, Structuring Your Code, Configuration, Spring Beans and Dependency Injection, DevTools, and more.
<<using-spring-boot.adoc#using,Using Spring Boot>> :: Build Systems, Structuring Your Code, Configuration, Spring Beans and Dependency Injection, DevTools, and more.
<<spring-boot-features.adoc#boot-features,Spring Boot Features>> :: Profiles, Logging, Security, Caching, Spring Integration, Testing, and more.
<<spring-boot-features.adoc#features,Spring Boot Features>> :: Profiles, Logging, Security, Caching, Spring Integration, Testing, and more.
<<production-ready-features.adoc#production-ready,Spring Boot Actuator>> :: Monitoring, Metrics, Auditing, and more.
<<production-ready-features.adoc#actuator,Spring Boot Actuator>> :: Monitoring, Metrics, Auditing, and more.
<<deployment.adoc#deployment,Deploying Spring Boot Applications>> :: Deploying to the Cloud, Installing as a Unix application.
<<deployment.adoc#deployment,Deploying Spring Boot Applications>> :: Deploying to the Cloud, Installing as a Unix application.
<<spring-boot-cli.adoc#cli,Spring Boot CLI>> :: Installing the CLI, Using the CLI, Configuring the CLI, and more.
<<spring-boot-cli.adoc#cli,Spring Boot CLI>> :: Installing the CLI, Using the CLI, Configuring the CLI, and more.
<<build-tool-plugins.adoc#build-tool-plugins,Build Tool Plugins>> :: Maven Plugin, Gradle Plugin, Antlib, and more.
<<build-tool-plugins.adoc#build-tool-plugins,Build Tool Plugins>> :: Maven Plugin, Gradle Plugin, Antlib, and more.
@@ -8,7 +8,7 @@ Auditing, health, and metrics gathering can also be automatically applied to you
...
@@ -8,7 +8,7 @@ Auditing, health, and metrics gathering can also be automatically applied to you
[[production-ready-enabling]]
[[actuator.enabling]]
== Enabling Production-ready Features
== Enabling Production-ready Features
The {spring-boot-code}/spring-boot-project/spring-boot-actuator[`spring-boot-actuator`] module provides all of Spring Boot's production-ready features.
The {spring-boot-code}/spring-boot-project/spring-boot-actuator[`spring-boot-actuator`] module provides all of Spring Boot's production-ready features.
The recommended way to enable the features is to add a dependency on the `spring-boot-starter-actuator` '`Starter`'.
The recommended way to enable the features is to add a dependency on the `spring-boot-starter-actuator` '`Starter`'.
...
@@ -42,13 +42,13 @@ For Gradle, use the following declaration:
...
@@ -42,13 +42,13 @@ For Gradle, use the following declaration:
[[production-ready-endpoints]]
[[actuator.endpoints]]
== Endpoints
== Endpoints
Actuator endpoints let you monitor and interact with your application.
Actuator endpoints let you monitor and interact with your application.
Spring Boot includes a number of built-in endpoints and lets you add your own.
Spring Boot includes a number of built-in endpoints and lets you add your own.
For example, the `health` endpoint provides basic application health information.
For example, the `health` endpoint provides basic application health information.
Each individual endpoint can be <<production-ready-endpoints-enabling-endpoints, enabled or disabled>> and <<production-ready-endpoints-exposing-endpoints, exposed (made remotely accessible) over HTTP or JMX>>.
Each individual endpoint can be <<actuator.endpoints.enabling, enabled or disabled>> and <<actuator.endpoints.exposing, exposed (made remotely accessible) over HTTP or JMX>>.
An endpoint is considered to be available when it is both enabled and exposed.
An endpoint is considered to be available when it is both enabled and exposed.
The built-in endpoints will only be auto-configured when they are available.
The built-in endpoints will only be auto-configured when they are available.
Most applications choose exposure via HTTP, where the ID of the endpoint along with a prefix of `/actuator` is mapped to a URL.
Most applications choose exposure via HTTP, where the ID of the endpoint along with a prefix of `/actuator` is mapped to a URL.
...
@@ -127,7 +127,7 @@ The following technology-agnostic endpoints are available:
...
@@ -127,7 +127,7 @@ The following technology-agnostic endpoints are available:
Disabled by default.
Disabled by default.
| `startup`
| `startup`
| Shows the <<spring-boot-features.adoc#boot-features-application-startup-tracking,startup steps data>> collected by the `ApplicationStartup`.
| Shows the <<spring-boot-features.adoc#features.spring-application.startup-tracking,startup steps data>> collected by the `ApplicationStartup`.
Requires the `SpringApplication` to be configured with a `BufferingApplicationStartup`.
Requires the `SpringApplication` to be configured with a `BufferingApplicationStartup`.
| `threaddump`
| `threaddump`
...
@@ -158,7 +158,7 @@ If your application is a web application (Spring MVC, Spring WebFlux, or Jersey)
...
@@ -158,7 +158,7 @@ If your application is a web application (Spring MVC, Spring WebFlux, or Jersey)
[[production-ready-endpoints-enabling-endpoints]]
[[actuator.endpoints.enabling]]
=== Enabling Endpoints
=== Enabling Endpoints
By default, all endpoints except for `shutdown` are enabled.
By default, all endpoints except for `shutdown` are enabled.
To configure the enablement of an endpoint, use its `management.endpoint.<id>.enabled` property.
To configure the enablement of an endpoint, use its `management.endpoint.<id>.enabled` property.
...
@@ -186,11 +186,11 @@ The following example enables the `info` endpoint and disables all other endpoin
...
@@ -186,11 +186,11 @@ The following example enables the `info` endpoint and disables all other endpoin
----
----
NOTE: Disabled endpoints are removed entirely from the application context.
NOTE: Disabled endpoints are removed entirely from the application context.
If you want to change only the technologies over which an endpoint is exposed, use the <<production-ready-endpoints-exposing-endpoints, `include` and `exclude` properties>> instead.
If you want to change only the technologies over which an endpoint is exposed, use the <<actuator.endpoints.exposing, `include` and `exclude` properties>> instead.
[[production-ready-endpoints-exposing-endpoints]]
[[actuator.endpoints.exposing]]
=== Exposing Endpoints
=== Exposing Endpoints
Since Endpoints may contain sensitive information, careful consideration should be given about when to expose them.
Since Endpoints may contain sensitive information, careful consideration should be given about when to expose them.
The following table shows the default exposure for the built-in endpoints:
The following table shows the default exposure for the built-in endpoints:
...
@@ -350,13 +350,13 @@ For example, to expose everything over HTTP except the `env` and `beans` endpoin
...
@@ -350,13 +350,13 @@ For example, to expose everything over HTTP except the `env` and `beans` endpoin
NOTE: `*` has a special meaning in YAML, so be sure to add quotes if you want to include (or exclude) all endpoints.
NOTE: `*` has a special meaning in YAML, so be sure to add quotes if you want to include (or exclude) all endpoints.
NOTE: If your application is exposed publicly, we strongly recommend that you also <<production-ready-endpoints-security, secure your endpoints>>.
NOTE: If your application is exposed publicly, we strongly recommend that you also <<actuator.endpoints.security, secure your endpoints>>.
TIP: If you want to implement your own strategy for when endpoints are exposed, you can register an `EndpointFilter` bean.
TIP: If you want to implement your own strategy for when endpoints are exposed, you can register an `EndpointFilter` bean.
[[production-ready-endpoints-security]]
[[actuator.endpoints.security]]
=== Securing HTTP Endpoints
=== Securing HTTP Endpoints
You should take care to secure HTTP endpoints in the same way that you would any other sensitive URL.
You should take care to secure HTTP endpoints in the same way that you would any other sensitive URL.
If Spring Security is present, endpoints are secured by default using Spring Security’s content-negotiation strategy.
If Spring Security is present, endpoints are secured by default using Spring Security’s content-negotiation strategy.
...
@@ -408,7 +408,7 @@ Since Spring Boot's security configuration backs off completely in the presence
...
@@ -408,7 +408,7 @@ Since Spring Boot's security configuration backs off completely in the presence
[[production-ready-endpoints-caching]]
[[actuator.endpoints.caching]]
=== Configuring Endpoints
=== Configuring Endpoints
Endpoints automatically cache responses to read operations that do not take any parameters.
Endpoints automatically cache responses to read operations that do not take any parameters.
To configure the amount of time for which an endpoint will cache a response, use its `cache.time-to-live` property.
To configure the amount of time for which an endpoint will cache a response, use its `cache.time-to-live` property.
...
@@ -427,7 +427,7 @@ NOTE: The prefix `management.endpoint.<name>` is used to uniquely identify the e
...
@@ -427,7 +427,7 @@ NOTE: The prefix `management.endpoint.<name>` is used to uniquely identify the e
[[production-ready-endpoints-hypermedia]]
[[actuator.endpoints.hypermedia]]
=== Hypermedia for Actuator Web Endpoints
=== Hypermedia for Actuator Web Endpoints
A "`discovery page`" is added with links to all the endpoints.
A "`discovery page`" is added with links to all the endpoints.
The "`discovery page`" is available on `/actuator` by default.
The "`discovery page`" is available on `/actuator` by default.
...
@@ -449,7 +449,7 @@ When the management context path is set to `/`, the discovery page is disabled t
...
@@ -449,7 +449,7 @@ When the management context path is set to `/`, the discovery page is disabled t
[[production-ready-endpoints-cors]]
[[actuator.endpoints.cors]]
=== CORS Support
=== CORS Support
https://en.wikipedia.org/wiki/Cross-origin_resource_sharing[Cross-origin resource sharing] (CORS) is a https://www.w3.org/TR/cors/[W3C specification] that lets you specify in a flexible way what kind of cross-domain requests are authorized.
https://en.wikipedia.org/wiki/Cross-origin_resource_sharing[Cross-origin resource sharing] (CORS) is a https://www.w3.org/TR/cors/[W3C specification] that lets you specify in a flexible way what kind of cross-domain requests are authorized.
If you use Spring MVC or Spring WebFlux, Actuator's web endpoints can be configured to support such scenarios.
If you use Spring MVC or Spring WebFlux, Actuator's web endpoints can be configured to support such scenarios.
...
@@ -471,7 +471,7 @@ TIP: See {spring-boot-actuator-autoconfigure-module-code}/endpoint/web/CorsEndpo
...
@@ -471,7 +471,7 @@ TIP: See {spring-boot-actuator-autoconfigure-module-code}/endpoint/web/CorsEndpo
[[production-ready-endpoints-custom]]
[[actuator.endpoints.implementing-custom]]
=== Implementing Custom Endpoints
=== Implementing Custom Endpoints
If you add a `@Bean` annotated with `@Endpoint`, any methods annotated with `@ReadOperation`, `@WriteOperation`, or `@DeleteOperation` are automatically exposed over JMX and, in a web application, over HTTP as well.
If you add a `@Bean` annotated with `@Endpoint`, any methods annotated with `@ReadOperation`, `@WriteOperation`, or `@DeleteOperation` are automatically exposed over JMX and, in a web application, over HTTP as well.
Endpoints can be exposed over HTTP using Jersey, Spring MVC, or Spring WebFlux.
Endpoints can be exposed over HTTP using Jersey, Spring MVC, or Spring WebFlux.
...
@@ -495,7 +495,7 @@ Finally, if you need access to web-framework-specific functionality, you can imp
...
@@ -495,7 +495,7 @@ Finally, if you need access to web-framework-specific functionality, you can imp
[[production-ready-endpoints-custom-input]]
[[actuator.endpoints.implementing-custom.input]]
==== Receiving Input
==== Receiving Input
Operations on an endpoint receive input via their parameters.
Operations on an endpoint receive input via their parameters.
When exposed via the web, the values for these parameters are taken from the URL's query parameters and from the JSON request body.
When exposed via the web, the values for these parameters are taken from the URL's query parameters and from the JSON request body.
...
@@ -529,27 +529,27 @@ This will happen automatically if you are using Spring Boot's Gradle plugin or i
...
@@ -529,27 +529,27 @@ This will happen automatically if you are using Spring Boot's Gradle plugin or i
The parameters passed to endpoint operation methods are, if necessary, automatically converted to the required type.
The parameters passed to endpoint operation methods are, if necessary, automatically converted to the required type.
Before calling an operation method, the input received via JMX or an HTTP request is converted to the required types using an instance of `ApplicationConversionService` as well as any `Converter` or `GenericConverter` beans qualified with `@EndpointConverter`.
Before calling an operation method, the input received via JMX or an HTTP request is converted to the required types using an instance of `ApplicationConversionService` as well as any `Converter` or `GenericConverter` beans qualified with `@EndpointConverter`.
[[production-ready-endpoints-custom-web]]
[[actuator.endpoints.implementing-custom.web]]
==== Custom Web Endpoints
==== Custom Web Endpoints
Operations on an `@Endpoint`, `@WebEndpoint`, or `@EndpointWebExtension` are automatically exposed over HTTP using Jersey, Spring MVC, or Spring WebFlux.
Operations on an `@Endpoint`, `@WebEndpoint`, or `@EndpointWebExtension` are automatically exposed over HTTP using Jersey, Spring MVC, or Spring WebFlux.
If both Jersey and Spring MVC are available, Spring MVC will be used.
If both Jersey and Spring MVC are available, Spring MVC will be used.
For a `@WriteOperation` (HTTP `POST`) that uses the request body, the consumes clause of the predicate is `application/vnd.spring-boot.actuator.v2+json, application/json`.
For a `@WriteOperation` (HTTP `POST`) that uses the request body, the consumes clause of the predicate is `application/vnd.spring-boot.actuator.v2+json, application/json`.
For all other operations the consumes clause is empty.
For all other operations the consumes clause is empty.
The produces clause of the predicate can be determined by the `produces` attribute of the `@DeleteOperation`, `@ReadOperation`, and `@WriteOperation` annotations.
The produces clause of the predicate can be determined by the `produces` attribute of the `@DeleteOperation`, `@ReadOperation`, and `@WriteOperation` annotations.
The attribute is optional.
The attribute is optional.
...
@@ -601,7 +601,7 @@ For all other operations the produces clause is `application/vnd.spring-boot.act
...
@@ -601,7 +601,7 @@ For all other operations the produces clause is `application/vnd.spring-boot.act
The default response status for an endpoint operation depends on the operation type (read, write, or delete) and what, if anything, the operation returns.
The default response status for an endpoint operation depends on the operation type (read, write, or delete) and what, if anything, the operation returns.
...
@@ -615,7 +615,7 @@ If an operation is invoked without a required parameter, or with a parameter tha
...
@@ -615,7 +615,7 @@ If an operation is invoked without a required parameter, or with a parameter tha
An operation on a web endpoint or a web-specific endpoint extension can receive the current `java.security.Principal` or `org.springframework.boot.actuate.endpoint.SecurityContext` as a method parameter.
An operation on a web endpoint or a web-specific endpoint extension can receive the current `java.security.Principal` or `org.springframework.boot.actuate.endpoint.SecurityContext` as a method parameter.
The former is typically used in conjunction with `@Nullable` to provide different behavior for authenticated and unauthenticated users.
The former is typically used in conjunction with `@Nullable` to provide different behavior for authenticated and unauthenticated users.
...
@@ -632,7 +632,7 @@ The latter is typically used to perform authorization checks using its `isUserIn
...
@@ -632,7 +632,7 @@ The latter is typically used to perform authorization checks using its `isUserIn
`@ControllerEndpoint` and `@RestControllerEndpoint` can be used to implement an endpoint that is only exposed by Spring MVC or Spring WebFlux.
`@ControllerEndpoint` and `@RestControllerEndpoint` can be used to implement an endpoint that is only exposed by Spring MVC or Spring WebFlux.
Methods are mapped using the standard annotations for Spring MVC and Spring WebFlux such as `@RequestMapping` and `@GetMapping`, with the endpoint's ID being used as a prefix for the path.
Methods are mapped using the standard annotations for Spring MVC and Spring WebFlux such as `@RequestMapping` and `@GetMapping`, with the endpoint's ID being used as a prefix for the path.
...
@@ -650,7 +650,7 @@ The `@Endpoint` and `@WebEndpoint` annotations should be preferred whenever poss
...
@@ -650,7 +650,7 @@ The `@Endpoint` and `@WebEndpoint` annotations should be preferred whenever poss
[[production-ready-health]]
[[actuator.endpoints.health]]
=== Health Information
=== Health Information
You can use health information to check the status of your running application.
You can use health information to check the status of your running application.
It is often used by monitoring software to alert someone when a production system goes down.
It is often used by monitoring software to alert someone when a production system goes down.
...
@@ -694,7 +694,7 @@ TIP: The `HealthContributorRegistry` can be used to register and unregister heal
...
@@ -694,7 +694,7 @@ TIP: The `HealthContributorRegistry` can be used to register and unregister heal
To provide custom health information, you can register Spring beans that implement the {spring-boot-actuator-module-code}/health/HealthIndicator.java[`HealthIndicator`] interface.
To provide custom health information, you can register Spring beans that implement the {spring-boot-actuator-module-code}/health/HealthIndicator.java[`HealthIndicator`] interface.
You need to provide an implementation of the `health()` method and return a `Health` response.
You need to provide an implementation of the `health()` method and return a `Health` response.
...
@@ -877,7 +877,7 @@ The following table shows the default status mappings for the built-in statuses:
...
@@ -877,7 +877,7 @@ The following table shows the default status mappings for the built-in statuses:
For reactive applications, such as those using Spring WebFlux, `ReactiveHealthContributor` provides a non-blocking contract for getting application health.
For reactive applications, such as those using Spring WebFlux, `ReactiveHealthContributor` provides a non-blocking contract for getting application health.
Similar to a traditional `HealthContributor`, health information is collected from the content of a {spring-boot-actuator-module-code}/health/ReactiveHealthContributorRegistry.java[`ReactiveHealthContributorRegistry`] (by default all {spring-boot-actuator-module-code}/health/HealthContributor.java[`HealthContributor`] and {spring-boot-actuator-module-code}/health/ReactiveHealthContributor.java[`ReactiveHealthContributor`] instances defined in your `ApplicationContext`).
Similar to a traditional `HealthContributor`, health information is collected from the content of a {spring-boot-actuator-module-code}/health/ReactiveHealthContributorRegistry.java[`ReactiveHealthContributorRegistry`] (by default all {spring-boot-actuator-module-code}/health/HealthContributor.java[`HealthContributor`] and {spring-boot-actuator-module-code}/health/ReactiveHealthContributor.java[`ReactiveHealthContributor`] instances defined in your `ApplicationContext`).
...
@@ -907,7 +907,7 @@ TIP: To handle the error automatically, consider extending from `AbstractReactiv
...
@@ -907,7 +907,7 @@ TIP: To handle the error automatically, consider extending from `AbstractReactiv
The following `ReactiveHealthIndicators` are auto-configured by Spring Boot when appropriate:
The following `ReactiveHealthIndicators` are auto-configured by Spring Boot when appropriate:
...
@@ -939,7 +939,7 @@ Also, any `HealthIndicator` that is not handled explicitly is wrapped automatica
...
@@ -939,7 +939,7 @@ Also, any `HealthIndicator` that is not handled explicitly is wrapped automatica
[[production-ready-health-groups]]
[[actuator.endpoints.health.groups]]
==== Health Groups
==== Health Groups
It's sometimes useful to organize health indicators into groups that can be used for different purposes.
It's sometimes useful to organize health indicators into groups that can be used for different purposes.
...
@@ -993,7 +993,7 @@ TIP: You can use `@Qualifier("groupname")` if you need to register custom `Statu
...
@@ -993,7 +993,7 @@ TIP: You can use `@Qualifier("groupname")` if you need to register custom `Statu
[[production-ready-health-datasource]]
[[actuator.endpoints.health.datasource]]
==== DataSource Health
==== DataSource Health
The `DataSource` health indicator shows the health of both standard data source and routing data source beans.
The `DataSource` health indicator shows the health of both standard data source and routing data source beans.
The health of a routing data source includes the health of each of its target data sources.
The health of a routing data source includes the health of each of its target data sources.
...
@@ -1002,15 +1002,15 @@ If you prefer not to include routing data sources in the indicator's output, set
...
@@ -1002,15 +1002,15 @@ If you prefer not to include routing data sources in the indicator's output, set
[[production-ready-kubernetes-probes]]
[[actuator.endpoints.kubernetes-probes]]
=== Kubernetes Probes
=== Kubernetes Probes
Applications deployed on Kubernetes can provide information about their internal state with https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes[Container Probes].
Applications deployed on Kubernetes can provide information about their internal state with https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes[Container Probes].
Depending on https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/[your Kubernetes configuration], the kubelet will call those probes and react to the result.
Depending on https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/[your Kubernetes configuration], the kubelet will call those probes and react to the result.
Spring Boot manages your <<spring-boot-features.adoc#boot-features-application-availability,Application Availability State>> out-of-the-box.
Spring Boot manages your <<spring-boot-features.adoc#features.spring-application.application-availability,Application Availability State>> out-of-the-box.
If deployed in a Kubernetes environment, actuator will gather the "Liveness" and "Readiness" information from the `ApplicationAvailability` interface and use that information in dedicated <<production-ready-health-indicators,Health Indicators>>: `LivenessStateHealthIndicator` and `ReadinessStateHealthIndicator`.
If deployed in a Kubernetes environment, actuator will gather the "Liveness" and "Readiness" information from the `ApplicationAvailability` interface and use that information in dedicated <<actuator.endpoints.health.auto-configured-health-indicators,Health Indicators>>: `LivenessStateHealthIndicator` and `ReadinessStateHealthIndicator`.
These indicators will be shown on the global health endpoint (`"/actuator/health"`).
These indicators will be shown on the global health endpoint (`"/actuator/health"`).
They will also be exposed as separate HTTP Probes using <<production-ready-health-groups, Health Groups>>: `"/actuator/health/liveness"` and `"/actuator/health/readiness"`.
They will also be exposed as separate HTTP Probes using <<actuator.endpoints.health.groups, Health Groups>>: `"/actuator/health/liveness"` and `"/actuator/health/readiness"`.
You can then configure your Kubernetes infrastructure with the following endpoint information:
You can then configure your Kubernetes infrastructure with the following endpoint information:
...
@@ -1034,20 +1034,20 @@ readinessProbe:
...
@@ -1034,20 +1034,20 @@ readinessProbe:
NOTE: `<actuator-port>` should be set to the port that the actuator endpoints are available on.
NOTE: `<actuator-port>` should be set to the port that the actuator endpoints are available on.
It could be the main web server port, or a separate management port if the `"management.server.port"` property has been set.
It could be the main web server port, or a separate management port if the `"management.server.port"` property has been set.
These health groups are only enabled automatically if the application is <<deployment.adoc#cloud-deployment-kubernetes,running in a Kubernetes environment>>.
These health groups are only enabled automatically if the application is <<deployment.adoc#deployment.cloud.kubernetes,running in a Kubernetes environment>>.
You can enable them in any environment using the configprop:management.endpoint.health.probes.enabled[] configuration property.
You can enable them in any environment using the configprop:management.endpoint.health.probes.enabled[] configuration property.
NOTE: If an application takes longer to start than the configured liveness period, Kubernetes mention the `"startupProbe"` as a possible solution.
NOTE: If an application takes longer to start than the configured liveness period, Kubernetes mention the `"startupProbe"` as a possible solution.
The `"startupProbe"` is not necessarily needed here as the `"readinessProbe"` fails until all startup tasks are done, see <<production-ready-features.adoc#production-ready-kubernetes-probes-lifecycle,how Probes behave during the application lifecycle>>.
The `"startupProbe"` is not necessarily needed here as the `"readinessProbe"` fails until all startup tasks are done, see <<production-ready-features.adoc#actuator.endpoints.kubernetes-probes.lifecycle,how Probes behave during the application lifecycle>>.
WARNING: If your Actuator endpoints are deployed on a separate management context, be aware that endpoints are then not using the same web infrastructure (port, connection pools, framework components) as the main application.
WARNING: If your Actuator endpoints are deployed on a separate management context, be aware that endpoints are then not using the same web infrastructure (port, connection pools, framework components) as the main application.
In this case, a probe check could be successful even if the main application does not work properly (for example, it cannot accept new connections).
In this case, a probe check could be successful even if the main application does not work properly (for example, it cannot accept new connections).
==== Checking External State with Kubernetes Probes
==== Checking External State with Kubernetes Probes
Actuator configures the "liveness" and "readiness" probes as Health Groups; this means that all the <<production-ready-health-groups, Health Groups features>> are available for them.
Actuator configures the "liveness" and "readiness" probes as Health Groups; this means that all the <<actuator.endpoints.health.groups, Health Groups features>> are available for them.
You can, for example, configure additional Health Indicators:
You can, for example, configure additional Health Indicators:
[source,yaml,indent=0,configprops,configblocks]
[source,yaml,indent=0,configprops,configblocks]
...
@@ -1063,11 +1063,11 @@ You can, for example, configure additional Health Indicators:
...
@@ -1063,11 +1063,11 @@ You can, for example, configure additional Health Indicators:
By default, Spring Boot does not add other Health Indicators to these groups.
By default, Spring Boot does not add other Health Indicators to these groups.
The "`liveness`" Probe should not depend on health checks for external systems.
The "`liveness`" Probe should not depend on health checks for external systems.
If the <<spring-boot-features.adoc#boot-features-application-availability-liveness-state,Liveness State of an application>> is broken, Kubernetes will try to solve that problem by restarting the application instance.
If the <<spring-boot-features.adoc#features.spring-application.application-availability.liveness,Liveness State of an application>> is broken, Kubernetes will try to solve that problem by restarting the application instance.
This means that if an external system fails (e.g. a database, a Web API, an external cache), Kubernetes might restart all application instances and create cascading failures.
This means that if an external system fails (e.g. a database, a Web API, an external cache), Kubernetes might restart all application instances and create cascading failures.
As for the "`readiness`" Probe, the choice of checking external systems must be made carefully by the application developers, i.e. Spring Boot does not include any additional health checks in the readiness probe.
As for the "`readiness`" Probe, the choice of checking external systems must be made carefully by the application developers, i.e. Spring Boot does not include any additional health checks in the readiness probe.
If the <<spring-boot-features.adoc#boot-features-application-availability-readiness-state,Readiness State of an application instance>> is unready, Kubernetes will not route traffic to that instance.
If the <<spring-boot-features.adoc#features.spring-application.application-availability.readiness,Readiness State of an application instance>> is unready, Kubernetes will not route traffic to that instance.
Some external systems might not be shared by application instances, in which case they could quite naturally be included in a readiness probe.
Some external systems might not be shared by application instances, in which case they could quite naturally be included in a readiness probe.
Other external systems might not be essential to the application (the application could have circuit breakers and fallbacks), in which case they definitely should not be included.
Other external systems might not be essential to the application (the application could have circuit breakers and fallbacks), in which case they definitely should not be included.
Unfortunately, an external system that is shared by all application instances is common, and you have to make a judgement call: include it in the readiness probe and expect that the application is taken out of service when the external service is down, or leave it out and deal with failures higher up the stack, e.g. using a circuit breaker in the caller.
Unfortunately, an external system that is shared by all application instances is common, and you have to make a judgement call: include it in the readiness probe and expect that the application is taken out of service when the external service is down, or leave it out and deal with failures higher up the stack, e.g. using a circuit breaker in the caller.
...
@@ -1082,13 +1082,13 @@ Also, if an application is using Kubernetes https://kubernetes.io/docs/tasks/run
...
@@ -1082,13 +1082,13 @@ Also, if an application is using Kubernetes https://kubernetes.io/docs/tasks/run
An important aspect of the Kubernetes Probes support is its consistency with the application lifecycle.
An important aspect of the Kubernetes Probes support is its consistency with the application lifecycle.
There is a significant difference between the `AvailabilityState` which is the in-memory, internal state of the application
There is a significant difference between the `AvailabilityState` which is the in-memory, internal state of the application
and the actual Probe which exposes that state: depending on the phase of application lifecycle, the Probe might not be available.
and the actual Probe which exposes that state: depending on the phase of application lifecycle, the Probe might not be available.
Spring Boot publishes <<spring-boot-features.adoc#boot-features-application-events-and-listeners,Application Events during startup and shutdown>>,
Spring Boot publishes <<spring-boot-features.adoc#features.spring-application.application-events-and-listeners,Application Events during startup and shutdown>>,
and Probes can listen to such events and expose the `AvailabilityState` information.
and Probes can listen to such events and expose the `AvailabilityState` information.
The following tables show the `AvailabilityState` and the state of HTTP connectors at different stages.
The following tables show the `AvailabilityState` and the state of HTTP connectors at different stages.
...
@@ -1134,7 +1134,7 @@ When a Spring Boot application shuts down:
...
@@ -1134,7 +1134,7 @@ When a Spring Boot application shuts down:
@@ -1143,18 +1143,18 @@ When a Spring Boot application shuts down:
...
@@ -1143,18 +1143,18 @@ When a Spring Boot application shuts down:
|The application context is closed and the application is shut down.
|The application context is closed and the application is shut down.
|===
|===
TIP: Check out the <<deployment.adoc#cloud-deployment-kubernetes-container-lifecycle,Kubernetes container lifecycle section>> for more information about Kubernetes deployment.
TIP: Check out the <<deployment.adoc#deployment.cloud.kubernetes.container-lifecycle,Kubernetes container lifecycle section>> for more information about Kubernetes deployment.
[[production-ready-application-info]]
[[actuator.endpoints.info]]
=== Application Information
=== Application Information
Application information exposes various information collected from all {spring-boot-actuator-module-code}/info/InfoContributor.java[`InfoContributor`] beans defined in your `ApplicationContext`.
Application information exposes various information collected from all {spring-boot-actuator-module-code}/info/InfoContributor.java[`InfoContributor`] beans defined in your `ApplicationContext`.
Spring Boot includes a number of auto-configured `InfoContributor` beans, and you can write your own.
Spring Boot includes a number of auto-configured `InfoContributor` beans, and you can write your own.
You can customize the data exposed by the `info` endpoint by setting `+info.*+` Spring properties.
You can customize the data exposed by the `info` endpoint by setting `+info.*+` Spring properties.
All `Environment` properties under the `info` key are automatically exposed.
All `Environment` properties under the `info` key are automatically exposed.
...
@@ -1194,7 +1194,7 @@ For example, you could add the following settings to your `application.propertie
...
@@ -1194,7 +1194,7 @@ For example, you could add the following settings to your `application.propertie
[TIP]
[TIP]
====
====
Rather than hardcoding those values, you could also <<howto.adoc#howto-automatic-expansion,expand info properties at build time>>.
Rather than hardcoding those values, you could also <<howto.adoc#howto.properties-and-configuration.expand-properties,expand info properties at build time>>.
Assuming you use Maven, you could rewrite the preceding example as follows:
Assuming you use Maven, you could rewrite the preceding example as follows:
...
@@ -1211,13 +1211,13 @@ Assuming you use Maven, you could rewrite the preceding example as follows:
...
@@ -1211,13 +1211,13 @@ Assuming you use Maven, you could rewrite the preceding example as follows:
Another useful feature of the `info` endpoint is its ability to publish information about the state of your `git` source code repository when the project was built.
Another useful feature of the `info` endpoint is its ability to publish information about the state of your `git` source code repository when the project was built.
If a `GitProperties` bean is available, the `info` endpoint can be used to expose these properties.
If a `GitProperties` bean is available, the `info` endpoint can be used to expose these properties.
TIP: A `GitProperties` bean is auto-configured if a `git.properties` file is available at the root of the classpath.
TIP: A `GitProperties` bean is auto-configured if a `git.properties` file is available at the root of the classpath.
See "<<howto.adoc#howto-git-info,Generate git information>>" for more details.
See "<<howto.adoc#howto.build.generate-git-info,Generate git information>>" for more details.
By default, the endpoint exposes `git.branch`, `git.commit.id`, and `git.commit.time` properties, if present.
By default, the endpoint exposes `git.branch`, `git.commit.id`, and `git.commit.time` properties, if present.
If you don't want any of these properties in the endpoint response, they need to be excluded from the `git.properties` file.
If you don't want any of these properties in the endpoint response, they need to be excluded from the `git.properties` file.
...
@@ -1240,17 +1240,17 @@ To disable the git commit information from the `info` endpoint completely, set t
...
@@ -1240,17 +1240,17 @@ To disable the git commit information from the `info` endpoint completely, set t
[[production-ready-application-info-build]]
[[actuator.endpoints.info.build-information]]
==== Build Information
==== Build Information
If a `BuildProperties` bean is available, the `info` endpoint can also publish information about your build.
If a `BuildProperties` bean is available, the `info` endpoint can also publish information about your build.
This happens if a `META-INF/build-info.properties` file is available in the classpath.
This happens if a `META-INF/build-info.properties` file is available in the classpath.
TIP: The Maven and Gradle plugins can both generate that file.
TIP: The Maven and Gradle plugins can both generate that file.
See "<<howto.adoc#howto-build-info,Generate build information>>" for more details.
See "<<howto.adoc#howto.build.generate-info,Generate build information>>" for more details.
To provide custom application information, you can register Spring beans that implement the {spring-boot-actuator-module-code}/info/InfoContributor.java[`InfoContributor`] interface.
To provide custom application information, you can register Spring beans that implement the {spring-boot-actuator-module-code}/info/InfoContributor.java[`InfoContributor`] interface.
...
@@ -1289,7 +1289,7 @@ If you reach the `info` endpoint, you should see a response that contains the fo
...
@@ -1289,7 +1289,7 @@ If you reach the `info` endpoint, you should see a response that contains the fo
[[production-ready-monitoring]]
[[actuator.monitoring]]
== Monitoring and Management over HTTP
== Monitoring and Management over HTTP
If you are developing a web application, Spring Boot Actuator auto-configures all enabled endpoints to be exposed over HTTP.
If you are developing a web application, Spring Boot Actuator auto-configures all enabled endpoints to be exposed over HTTP.
The default convention is to use the `id` of the endpoint with a prefix of `/actuator` as the URL path.
The default convention is to use the `id` of the endpoint with a prefix of `/actuator` as the URL path.
...
@@ -1302,7 +1302,7 @@ NOTE: Jackson is a required dependency in order to get the correct JSON response
...
@@ -1302,7 +1302,7 @@ NOTE: Jackson is a required dependency in order to get the correct JSON response
Sometimes, it is useful to customize the prefix for the management endpoints.
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.
...
@@ -1318,7 +1318,7 @@ You can use the configprop:management.endpoints.web.base-path[] property to chan
...
@@ -1318,7 +1318,7 @@ You can use the configprop:management.endpoints.web.base-path[] property to chan
The preceding `application.properties` example changes the endpoint from `/actuator/\{id}` to `/manage/\{id}` (for example, `/manage/info`).
The preceding `application.properties` example changes the endpoint from `/actuator/\{id}` to `/manage/\{id}` (for example, `/manage/info`).
NOTE: Unless the management port has been configured to <<production-ready-customizing-management-server-port,expose endpoints by using a different HTTP port>>, `management.endpoints.web.base-path` is relative to `server.servlet.context-path` (Servlet web applications) or `spring.webflux.base-path` (reactive web applications).
NOTE: Unless the management port has been configured to <<actuator.monitoring.customizing-management-server-port,expose endpoints by using a different HTTP port>>, `management.endpoints.web.base-path` is relative to `server.servlet.context-path` (Servlet web applications) or `spring.webflux.base-path` (reactive web applications).
If `management.server.port` is configured, `management.endpoints.web.base-path` is relative to `management.server.base-path`.
If `management.server.port` is configured, `management.endpoints.web.base-path` is relative to `management.server.base-path`.
If you want to map endpoints to a different path, you can use the configprop:management.endpoints.web.path-mapping[] property.
If you want to map endpoints to a different path, you can use the configprop:management.endpoints.web.path-mapping[] property.
...
@@ -1337,7 +1337,7 @@ The following example remaps `/actuator/health` to `/healthcheck`:
...
@@ -1337,7 +1337,7 @@ The following example remaps `/actuator/health` to `/healthcheck`:
Exposing management endpoints by using the default HTTP port is a sensible choice for cloud-based deployments.
Exposing management endpoints by using the default HTTP port is a sensible choice for cloud-based deployments.
If, however, your application runs inside your own data center, you may prefer to expose endpoints by using a different HTTP port.
If, however, your application runs inside your own data center, you may prefer to expose endpoints by using a different HTTP port.
...
@@ -1356,7 +1356,7 @@ If you want to use a custom management port on Cloud Foundry, you will need to e
...
@@ -1356,7 +1356,7 @@ If you want to use a custom management port on Cloud Foundry, you will need to e
[[production-ready-management-specific-ssl]]
[[actuator.monitoring.management-specific-ssl]]
=== Configuring Management-specific SSL
=== Configuring Management-specific SSL
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:
...
@@ -1397,7 +1397,7 @@ Alternatively, both the main server and the management server can use SSL but wi
...
@@ -1397,7 +1397,7 @@ Alternatively, both the main server and the management server can use SSL but wi
You can customize the address that the management endpoints are available on by setting the configprop:management.server.address[] property.
You can customize the address that the management endpoints are available on by setting the configprop:management.server.address[] property.
Doing so can be useful if you want to listen only on an internal or ops-facing network or to listen only for connections from `localhost`.
Doing so can be useful if you want to listen only on an internal or ops-facing network or to listen only for connections from `localhost`.
...
@@ -1416,7 +1416,7 @@ The following example `application.properties` does not allow remote management
...
@@ -1416,7 +1416,7 @@ The following example `application.properties` does not allow remote management
[[production-ready-disabling-http-endpoints]]
[[actuator.monitoring.disabling-http-endpoints]]
=== 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:
...
@@ -1440,7 +1440,7 @@ This can be achieved using the configprop:management.endpoints.web.exposure.excl
...
@@ -1440,7 +1440,7 @@ This can be achieved using the configprop:management.endpoints.web.exposure.excl
[[production-ready-jmx]]
[[actuator.jmx]]
== Monitoring and Management over JMX
== Monitoring and Management over JMX
Java Management Extensions (JMX) provide a standard mechanism to monitor and manage applications.
Java Management Extensions (JMX) provide a standard mechanism to monitor and manage applications.
By default, this feature is not enabled and can be turned on by setting the configuration property configprop:spring.jmx.enabled[] to `true`.
By default, this feature is not enabled and can be turned on by setting the configuration property configprop:spring.jmx.enabled[] to `true`.
...
@@ -1449,7 +1449,7 @@ To Take full control over endpoints registration in the JMX domain, consider reg
...
@@ -1449,7 +1449,7 @@ To Take full control over endpoints registration in the JMX domain, consider reg
[[production-ready-custom-mbean-names]]
[[actuator.jmx.custom-mbean-names]]
=== Customizing MBean Names
=== Customizing MBean Names
The name of the MBean is usually generated from the `id` of the endpoint.
The name of the MBean is usually generated from the `id` of the endpoint.
For example, the `health` endpoint is exposed as `org.springframework.boot:type=Endpoint,name=Health`.
For example, the `health` endpoint is exposed as `org.springframework.boot:type=Endpoint,name=Health`.
...
@@ -1473,7 +1473,7 @@ The following settings show an example of doing so in `application.properties`:
...
@@ -1473,7 +1473,7 @@ The following settings show an example of doing so in `application.properties`:
[[production-ready-disable-jmx-endpoints]]
[[actuator.jmx.disable-jmx-endpoints]]
=== 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:
...
@@ -1488,7 +1488,7 @@ If you do not want to expose endpoints over JMX, you can set the configprop:mana
...
@@ -1488,7 +1488,7 @@ If you do not want to expose endpoints over JMX, you can set the configprop:mana
[[production-ready-jolokia]]
[[actuator.jmx.jolokia]]
=== Using Jolokia for JMX over HTTP
=== Using Jolokia for JMX over HTTP
Jolokia is a JMX-HTTP bridge that provides an alternative method of accessing JMX beans.
Jolokia is a JMX-HTTP bridge that provides an alternative method of accessing JMX beans.
To use Jolokia, include a dependency to `org.jolokia:jolokia-core`.
To use Jolokia, include a dependency to `org.jolokia:jolokia-core`.
...
@@ -1511,7 +1511,7 @@ The endpoint will not be available in a WebFlux application.
...
@@ -1511,7 +1511,7 @@ The endpoint will not be available in a WebFlux application.
[[production-ready-customizing-jolokia]]
[[actuator.jmx.jolokia.customizing]]
==== Customizing Jolokia
==== Customizing Jolokia
Jolokia has a number of settings that you would traditionally configure by setting servlet parameters.
Jolokia has a number of settings that you would traditionally configure by setting servlet parameters.
With Spring Boot, you can use your `application.properties` file.
With Spring Boot, you can use your `application.properties` file.
...
@@ -1528,7 +1528,7 @@ To do so, prefix the parameter with `management.endpoint.jolokia.config.`, as sh
...
@@ -1528,7 +1528,7 @@ To do so, prefix the parameter with `management.endpoint.jolokia.config.`, as sh
[[production-ready-disabling-jolokia]]
[[actuator.jmx.jolokia.disabling]]
==== 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:
...
@@ -1542,7 +1542,7 @@ If you use Jolokia but do not want Spring Boot to configure it, set the configpr
...
@@ -1542,7 +1542,7 @@ If you use Jolokia but do not want Spring Boot to configure it, set the configpr
[[production-ready-loggers]]
[[actuator.loggers]]
== Loggers
== Loggers
Spring Boot Actuator includes the ability to view and configure the log levels of your application at runtime.
Spring Boot Actuator includes the ability to view and configure the log levels of your application at runtime.
You can view either the entire list or an individual logger's configuration, which is made up of both the explicitly configured logging level as well as the effective logging level given to it by the logging framework.
You can view either the entire list or an individual logger's configuration, which is made up of both the explicitly configured logging level as well as the effective logging level given to it by the logging framework.
...
@@ -1561,7 +1561,7 @@ These levels can be one of:
...
@@ -1561,7 +1561,7 @@ These levels can be one of:
[[production-ready-logger-configuration]]
[[actuator.loggers.configure]]
=== 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:
...
@@ -1576,34 +1576,34 @@ TIP: To "`reset`" the specific level of the logger (and use the default configur
...
@@ -1576,34 +1576,34 @@ TIP: To "`reset`" the specific level of the logger (and use the default configur
[[production-ready-metrics]]
[[actuator.metrics]]
== Metrics
== Metrics
Spring Boot Actuator provides dependency management and auto-configuration for https://micrometer.io[Micrometer], an application metrics facade that supports {micrometer-docs}[numerous monitoring systems], including:
Spring Boot Actuator provides dependency management and auto-configuration for https://micrometer.io[Micrometer], an application metrics facade that supports {micrometer-docs}[numerous monitoring systems], including:
TIP: To learn more about Micrometer's capabilities, please refer to its https://micrometer.io/docs[reference documentation], in particular the {micrometer-concepts-docs}[concepts section].
TIP: To learn more about Micrometer's capabilities, please refer to its https://micrometer.io/docs[reference documentation], in particular the {micrometer-concepts-docs}[concepts section].
[[production-ready-metrics-getting-started]]
[[actuator.metrics.getting-started]]
=== Getting started
=== Getting started
Spring Boot auto-configures a composite `MeterRegistry` and adds a registry to the composite for each of the supported implementations that it finds on the classpath.
Spring Boot auto-configures a composite `MeterRegistry` and adds a registry to the composite for each of the supported implementations that it finds on the classpath.
Having a dependency on `micrometer-registry-\{system}` in your runtime classpath is enough for Spring Boot to configure the registry.
Having a dependency on `micrometer-registry-\{system}` in your runtime classpath is enough for Spring Boot to configure the registry.
...
@@ -1661,16 +1661,16 @@ You can apply customizations to particular registry implementations by being mor
...
@@ -1661,16 +1661,16 @@ You can apply customizations to particular registry implementations by being mor
}
}
----
----
Spring Boot also <<production-ready-metrics-meter,configures built-in instrumentation>> that you can control via configuration or dedicated annotation markers.
Spring Boot also <<actuator.metrics.supported,configures built-in instrumentation>> that you can control via configuration or dedicated annotation markers.
[[production-ready-metrics-export]]
[[actuator.metrics.export]]
=== Supported Monitoring Systems
=== Supported Monitoring Systems
[[production-ready-metrics-export-appoptics]]
[[actuator.metrics.export.appoptics]]
==== AppOptics
==== AppOptics
By default, the AppOptics registry pushes metrics to `https://api.appoptics.com/v1/measurements` periodically.
By default, the AppOptics registry pushes metrics to `https://api.appoptics.com/v1/measurements` periodically.
To export metrics to SaaS {micrometer-registry-docs}/appOptics[AppOptics], your API token must be provided:
To export metrics to SaaS {micrometer-registry-docs}/appOptics[AppOptics], your API token must be provided:
...
@@ -1686,7 +1686,7 @@ To export metrics to SaaS {micrometer-registry-docs}/appOptics[AppOptics], your
...
@@ -1686,7 +1686,7 @@ To export metrics to SaaS {micrometer-registry-docs}/appOptics[AppOptics], your
[[production-ready-metrics-export-atlas]]
[[actuator.metrics.export.atlas]]
==== Atlas
==== Atlas
By default, metrics are exported to {micrometer-registry-docs}/atlas[Atlas] running on your local machine.
By default, metrics are exported to {micrometer-registry-docs}/atlas[Atlas] running on your local machine.
The location of the https://github.com/Netflix/atlas[Atlas server] to use can be provided using:
The location of the https://github.com/Netflix/atlas[Atlas server] to use can be provided using:
...
@@ -1702,7 +1702,7 @@ The location of the https://github.com/Netflix/atlas[Atlas server] to use can be
...
@@ -1702,7 +1702,7 @@ The location of the https://github.com/Netflix/atlas[Atlas server] to use can be
[[production-ready-metrics-export-datadog]]
[[actuator.metrics.export.datadog]]
==== Datadog
==== Datadog
Datadog registry pushes metrics to https://www.datadoghq.com[datadoghq] periodically.
Datadog registry pushes metrics to https://www.datadoghq.com[datadoghq] periodically.
To export metrics to {micrometer-registry-docs}/datadog[Datadog], your API key must be provided:
To export metrics to {micrometer-registry-docs}/datadog[Datadog], your API key must be provided:
...
@@ -1729,7 +1729,7 @@ You can also change the interval at which metrics are sent to Datadog:
...
@@ -1729,7 +1729,7 @@ You can also change the interval at which metrics are sent to Datadog:
[[production-ready-metrics-export-dynatrace]]
[[actuator.metrics.export.dynatrace]]
==== Dynatrace
==== Dynatrace
Dynatrace registry pushes metrics to the configured URI periodically.
Dynatrace registry pushes metrics to the configured URI periodically.
To export metrics to {micrometer-registry-docs}/dynatrace[Dynatrace], your API token, device ID, and URI must be provided:
To export metrics to {micrometer-registry-docs}/dynatrace[Dynatrace], your API token, device ID, and URI must be provided:
...
@@ -1758,7 +1758,7 @@ You can also change the interval at which metrics are sent to Dynatrace:
...
@@ -1758,7 +1758,7 @@ You can also change the interval at which metrics are sent to Dynatrace:
[[production-ready-metrics-export-elastic]]
[[actuator.metrics.export.elastic]]
==== Elastic
==== Elastic
By default, metrics are exported to {micrometer-registry-docs}/elastic[Elastic] running on your local machine.
By default, metrics are exported to {micrometer-registry-docs}/elastic[Elastic] running on your local machine.
The location of the Elastic server to use can be provided using the following property:
The location of the Elastic server to use can be provided using the following property:
...
@@ -1774,7 +1774,7 @@ The location of the Elastic server to use can be provided using the following pr
...
@@ -1774,7 +1774,7 @@ The location of the Elastic server to use can be provided using the following pr
[[production-ready-metrics-export-ganglia]]
[[actuator.metrics.export.ganglia]]
==== Ganglia
==== Ganglia
By default, metrics are exported to {micrometer-registry-docs}/ganglia[Ganglia] running on your local machine.
By default, metrics are exported to {micrometer-registry-docs}/ganglia[Ganglia] running on your local machine.
The http://ganglia.sourceforge.net[Ganglia server] host and port to use can be provided using:
The http://ganglia.sourceforge.net[Ganglia server] host and port to use can be provided using:
...
@@ -1791,7 +1791,7 @@ The http://ganglia.sourceforge.net[Ganglia server] host and port to use can be p
...
@@ -1791,7 +1791,7 @@ The http://ganglia.sourceforge.net[Ganglia server] host and port to use can be p
[[production-ready-metrics-export-graphite]]
[[actuator.metrics.export.graphite]]
==== Graphite
==== Graphite
By default, metrics are exported to {micrometer-registry-docs}/graphite[Graphite] running on your local machine.
By default, metrics are exported to {micrometer-registry-docs}/graphite[Graphite] running on your local machine.
The https://graphiteapp.org[Graphite server] host and port to use can be provided using:
The https://graphiteapp.org[Graphite server] host and port to use can be provided using:
...
@@ -1821,7 +1821,7 @@ An auto-configured `GraphiteConfig` and `Clock` beans are provided unless you de
...
@@ -1821,7 +1821,7 @@ An auto-configured `GraphiteConfig` and `Clock` beans are provided unless you de
[[production-ready-metrics-export-humio]]
[[actuator.metrics.export.humio]]
==== Humio
==== Humio
By default, the Humio registry pushes metrics to https://cloud.humio.com periodically.
By default, the Humio registry pushes metrics to https://cloud.humio.com periodically.
To export metrics to SaaS {micrometer-registry-docs}/humio[Humio], your API token must be provided:
To export metrics to SaaS {micrometer-registry-docs}/humio[Humio], your API token must be provided:
...
@@ -1850,7 +1850,7 @@ You should also configure one or more tags to identify the data source to which
...
@@ -1850,7 +1850,7 @@ You should also configure one or more tags to identify the data source to which
[[production-ready-metrics-export-influx]]
[[actuator.metrics.export.influx]]
==== Influx
==== Influx
By default, metrics are exported to an {micrometer-registry-docs}/influx[Influx] v1 instance running on your local machine with the default configuration.
By default, metrics are exported to an {micrometer-registry-docs}/influx[Influx] v1 instance running on your local machine with the default configuration.
To export metrics to InfluxDB v2, configure the `org`, `bucket`, and authentication `token` for writing metrics.
To export metrics to InfluxDB v2, configure the `org`, `bucket`, and authentication `token` for writing metrics.
...
@@ -1867,7 +1867,7 @@ The location of the https://www.influxdata.com[Influx server] to use can be prov
...
@@ -1867,7 +1867,7 @@ The location of the https://www.influxdata.com[Influx server] to use can be prov
[[production-ready-metrics-export-jmx]]
[[actuator.metrics.export.jmx]]
==== JMX
==== JMX
Micrometer provides a hierarchical mapping to {micrometer-registry-docs}/jmx[JMX], primarily as a cheap and portable way to view metrics locally.
Micrometer provides a hierarchical mapping to {micrometer-registry-docs}/jmx[JMX], primarily as a cheap and portable way to view metrics locally.
By default, metrics are exported to the `metrics` JMX domain.
By default, metrics are exported to the `metrics` JMX domain.
...
@@ -1897,7 +1897,7 @@ An auto-configured `JmxConfig` and `Clock` beans are provided unless you define
...
@@ -1897,7 +1897,7 @@ An auto-configured `JmxConfig` and `Clock` beans are provided unless you define
[[production-ready-metrics-export-kairos]]
[[actuator.metrics.export.kairos]]
==== KairosDB
==== KairosDB
By default, metrics are exported to {micrometer-registry-docs}/kairos[KairosDB] running on your local machine.
By default, metrics are exported to {micrometer-registry-docs}/kairos[KairosDB] running on your local machine.
The location of the https://kairosdb.github.io/[KairosDB server] to use can be provided using:
The location of the https://kairosdb.github.io/[KairosDB server] to use can be provided using:
...
@@ -1913,7 +1913,7 @@ The location of the https://kairosdb.github.io/[KairosDB server] to use can be p
...
@@ -1913,7 +1913,7 @@ The location of the https://kairosdb.github.io/[KairosDB server] to use can be p
[[production-ready-metrics-export-newrelic]]
[[actuator.metrics.export.newrelic]]
==== New Relic
==== New Relic
New Relic registry pushes metrics to {micrometer-registry-docs}/new-relic[New Relic] periodically.
New Relic registry pushes metrics to {micrometer-registry-docs}/new-relic[New Relic] periodically.
To export metrics to https://newrelic.com[New Relic], your API key and account id must be provided:
To export metrics to https://newrelic.com[New Relic], your API key and account id must be provided:
...
@@ -1954,12 +1954,12 @@ Finally, you can take full control by defining your own `NewRelicClientProvider`
...
@@ -1954,12 +1954,12 @@ Finally, you can take full control by defining your own `NewRelicClientProvider`
[[production-ready-metrics-export-prometheus]]
[[actuator.metrics.export.prometheus]]
==== Prometheus
==== Prometheus
{micrometer-registry-docs}/prometheus[Prometheus] expects to scrape or poll individual app instances for metrics.
{micrometer-registry-docs}/prometheus[Prometheus] expects to scrape or poll individual app instances for metrics.
Spring Boot provides an actuator endpoint available at `/actuator/prometheus` to present a https://prometheus.io[Prometheus scrape] with the appropriate format.
Spring Boot provides an actuator endpoint available at `/actuator/prometheus` to present a https://prometheus.io[Prometheus scrape] with the appropriate format.
TIP: The endpoint is not available by default and must be exposed, see <<production-ready-endpoints-exposing-endpoints,exposing endpoints>> for more details.
TIP: The endpoint is not available by default and must be exposed, see <<actuator.endpoints.exposing,exposing endpoints>> for more details.
Here is an example `scrape_config` to add to `prometheus.yml`:
Here is an example `scrape_config` to add to `prometheus.yml`:
...
@@ -1991,7 +1991,7 @@ For advanced configuration, you can also provide your own `PrometheusPushGateway
...
@@ -1991,7 +1991,7 @@ For advanced configuration, you can also provide your own `PrometheusPushGateway
[[production-ready-metrics-export-signalfx]]
[[actuator.metrics.export.signalfx]]
==== SignalFx
==== SignalFx
SignalFx registry pushes metrics to {micrometer-registry-docs}/signalFx[SignalFx] periodically.
SignalFx registry pushes metrics to {micrometer-registry-docs}/signalFx[SignalFx] periodically.
To export metrics to https://www.signalfx.com[SignalFx], your access token must be provided:
To export metrics to https://www.signalfx.com[SignalFx], your access token must be provided:
...
@@ -2018,10 +2018,10 @@ You can also change the interval at which metrics are sent to SignalFx:
...
@@ -2018,10 +2018,10 @@ You can also change the interval at which metrics are sent to SignalFx:
[[production-ready-metrics-export-simple]]
[[actuator.metrics.export.simple]]
==== Simple
==== Simple
Micrometer ships with a simple, in-memory backend that is automatically used as a fallback if no other registry is configured.
Micrometer ships with a simple, in-memory backend that is automatically used as a fallback if no other registry is configured.
This allows you to see what metrics are collected in the <<production-ready-metrics-endpoint,metrics endpoint>>.
This allows you to see what metrics are collected in the <<actuator.metrics.endpoint,metrics endpoint>>.
The in-memory backend disables itself as soon as you're using any of the other available backend.
The in-memory backend disables itself as soon as you're using any of the other available backend.
You can also disable it explicitly:
You can also disable it explicitly:
...
@@ -2037,7 +2037,7 @@ You can also disable it explicitly:
...
@@ -2037,7 +2037,7 @@ You can also disable it explicitly:
[[production-ready-metrics-export-stackdriver]]
[[actuator.metrics.export.stackdriver]]
==== Stackdriver
==== Stackdriver
Stackdriver registry pushes metrics to https://cloud.google.com/stackdriver/[Stackdriver] periodically.
Stackdriver registry pushes metrics to https://cloud.google.com/stackdriver/[Stackdriver] periodically.
To export metrics to SaaS {micrometer-registry-docs}/stackdriver[Stackdriver], your Google Cloud project id must be provided:
To export metrics to SaaS {micrometer-registry-docs}/stackdriver[Stackdriver], your Google Cloud project id must be provided:
...
@@ -2064,7 +2064,7 @@ You can also change the interval at which metrics are sent to Stackdriver:
...
@@ -2064,7 +2064,7 @@ You can also change the interval at which metrics are sent to Stackdriver:
[[production-ready-metrics-export-statsd]]
[[actuator.metrics.export.statsd]]
==== StatsD
==== StatsD
The StatsD registry pushes metrics over UDP to a StatsD agent eagerly.
The StatsD registry pushes metrics over UDP to a StatsD agent eagerly.
By default, metrics are exported to a {micrometer-registry-docs}/statsD[StatsD] agent running on your local machine.
By default, metrics are exported to a {micrometer-registry-docs}/statsD[StatsD] agent running on your local machine.
...
@@ -2094,7 +2094,7 @@ You can also change the StatsD line protocol to use (default to Datadog):
...
@@ -2094,7 +2094,7 @@ You can also change the StatsD line protocol to use (default to Datadog):
[[production-ready-metrics-export-wavefront]]
[[actuator.metrics.export.wavefront]]
==== Wavefront
==== Wavefront
Wavefront registry pushes metrics to {micrometer-registry-docs}/wavefront[Wavefront] periodically.
Wavefront registry pushes metrics to {micrometer-registry-docs}/wavefront[Wavefront] periodically.
If you are exporting metrics to https://www.wavefront.com/[Wavefront] directly, your API token must be provided:
If you are exporting metrics to https://www.wavefront.com/[Wavefront] directly, your API token must be provided:
...
@@ -2134,14 +2134,14 @@ You can also change the interval at which metrics are sent to Wavefront:
...
@@ -2134,14 +2134,14 @@ You can also change the interval at which metrics are sent to Wavefront:
[[production-ready-metrics-meter]]
[[actuator.metrics.supported]]
=== Supported Metrics and Meters
=== Supported Metrics and Meters
Spring Boot provides automatic meter registration for a wide variety of technologies.
Spring Boot provides automatic meter registration for a wide variety of technologies.
In most situations, the out-of-the-box defaults will provide sensible metrics that can be published to any of the supported monioring systems.
In most situations, the out-of-the-box defaults will provide sensible metrics that can be published to any of the supported monioring systems.
[[production-ready-metrics-jvm]]
[[actuator.metrics.supported.jvm]]
==== JVM Metrics
==== JVM Metrics
Auto-configuration will enable JVM Metrics using core Micrometer classes.
Auto-configuration will enable JVM Metrics using core Micrometer classes.
JVM metrics are published under the `jvm.` meter name.
JVM metrics are published under the `jvm.` meter name.
...
@@ -2155,7 +2155,7 @@ The following JVM metrics are provided:
...
@@ -2155,7 +2155,7 @@ The following JVM metrics are provided:
[[production-ready-metrics-system]]
[[actuator.metrics.supported.system]]
==== System Metrics
==== System Metrics
Auto-configuration will enable system metrics using core Micrometer classes.
Auto-configuration will enable system metrics using core Micrometer classes.
System metrics are published under the `system.` and `process.` meter names.
System metrics are published under the `system.` and `process.` meter names.
...
@@ -2168,20 +2168,20 @@ The following system metrics are provided:
...
@@ -2168,20 +2168,20 @@ The following system metrics are provided:
[[production-ready-metrics-logger]]
[[actuator.metrics.supported.logger]]
==== Logger Metrics
==== Logger Metrics
Auto-configuration enables the event metrics for both Logback and Log4J2.
Auto-configuration enables the event metrics for both Logback and Log4J2.
Details are published under the `log4j2.events.` or `logback.events.` meter names.
Details are published under the `log4j2.events.` or `logback.events.` meter names.
[[production-ready-metrics-spring-mvc]]
[[actuator.metrics.supported.spring-mvc]]
==== Spring MVC Metrics
==== Spring MVC Metrics
Auto-configuration enables the instrumentation of all requests handled by Spring MVC controllers and functional handlers.
Auto-configuration enables the instrumentation of all requests handled by Spring MVC controllers and functional handlers.
By default, metrics are generated with the name, `http.server.requests`.
By default, metrics are generated with the name, `http.server.requests`.
The name can be customized by setting the configprop:management.metrics.web.server.request.metric-name[] property.
The name can be customized by setting the configprop:management.metrics.web.server.request.metric-name[] property.
`@Timed` annotations are supported on `@Controller` classes and `@RequestMapping` methods (see <<production-ready-metrics-timed-annotation>> for details).
`@Timed` annotations are supported on `@Controller` classes and `@RequestMapping` methods (see <<actuator.metrics.supported.timed-annotation>> for details).
If you don't want to record metrics for all Spring MVC requests, you can set configprop:management.metrics.web.server.request.autotime.enabled[] to `false` and exclusively use `@Timed` annotations instead.
If you don't want to record metrics for all Spring MVC requests, you can set configprop:management.metrics.web.server.request.autotime.enabled[] to `false` and exclusively use `@Timed` annotations instead.
By default, Spring MVC related metrics are tagged with the following information:
By default, Spring MVC related metrics are tagged with the following information:
...
@@ -2210,17 +2210,17 @@ To add to the default tags, provide one or more ``@Bean``s that implement `WebMv
...
@@ -2210,17 +2210,17 @@ To add to the default tags, provide one or more ``@Bean``s that implement `WebMv
To replace the default tags, provide a `@Bean` that implements `WebMvcTagsProvider`.
To replace the default tags, provide a `@Bean` that implements `WebMvcTagsProvider`.
TIP: In some cases, exceptions handled in Web controllers are not recorded as request metrics tags.
TIP: In some cases, exceptions handled in Web controllers are not recorded as request metrics tags.
Applications can opt-in and record exceptions by <<spring-boot-features.adoc#boot-features-error-handling, setting handled exceptions as request attributes>>.
Applications can opt-in and record exceptions by <<spring-boot-features.adoc#features.developing-web-applications.spring-mvc.error-handling, setting handled exceptions as request attributes>>.
[[production-ready-metrics-web-flux]]
[[actuator.metrics.supported.spring-webflux]]
==== Spring WebFlux Metrics
==== Spring WebFlux Metrics
Auto-configuration enables the instrumentation of all requests handled by Spring WebFlux controllers and functional handlers.
Auto-configuration enables the instrumentation of all requests handled by Spring WebFlux controllers and functional handlers.
By default, metrics are generated with the name, `http.server.requests`.
By default, metrics are generated with the name, `http.server.requests`.
The name can be customized by setting the configprop:management.metrics.web.server.request.metric-name[] property.
The name can be customized by setting the configprop:management.metrics.web.server.request.metric-name[] property.
`@Timed` annotations are supported on `@Controller` classes and `@RequestMapping` methods (see <<production-ready-metrics-timed-annotation>> for details).
`@Timed` annotations are supported on `@Controller` classes and `@RequestMapping` methods (see <<actuator.metrics.supported.timed-annotation>> for details).
If you don't want to record metrics for all Spring WebFlux requests, you can set configprop:management.metrics.web.server.request.autotime.enabled[] to `false` and exclusively use `@Timed` annotations instead.
If you don't want to record metrics for all Spring WebFlux requests, you can set configprop:management.metrics.web.server.request.autotime.enabled[] to `false` and exclusively use `@Timed` annotations instead.
By default, WebFlux related metrics are tagged with the following information:
By default, WebFlux related metrics are tagged with the following information:
...
@@ -2249,17 +2249,17 @@ To add to the default tags, provide one or more ``@Bean``s that implement `WebFl
...
@@ -2249,17 +2249,17 @@ To add to the default tags, provide one or more ``@Bean``s that implement `WebFl
To replace the default tags, provide a `@Bean` that implements `WebFluxTagsProvider`.
To replace the default tags, provide a `@Bean` that implements `WebFluxTagsProvider`.
TIP: In some cases, exceptions handled in controllers and handler functions are not recorded as request metrics tags.
TIP: In some cases, exceptions handled in controllers and handler functions are not recorded as request metrics tags.
Applications can opt-in and record exceptions by <<spring-boot-features.adoc#boot-features-webflux-error-handling, setting handled exceptions as request attributes>>.
Applications can opt-in and record exceptions by <<spring-boot-features.adoc#features.developing-web-applications.spring-webflux.error-handling, setting handled exceptions as request attributes>>.
[[production-ready-metrics-jersey-server]]
[[actuator.metrics.supported.jersey]]
==== Jersey Server Metrics
==== Jersey Server Metrics
Auto-configuration enables the instrumentation of all requests handled by the Jersey JAX-RS implementation whenever Micrometer's `micrometer-jersey2` module is on the classpath.
Auto-configuration enables the instrumentation of all requests handled by the Jersey JAX-RS implementation whenever Micrometer's `micrometer-jersey2` module is on the classpath.
By default, metrics are generated with the name, `http.server.requests`.
By default, metrics are generated with the name, `http.server.requests`.
The name can be customized by setting the configprop:management.metrics.web.server.request.metric-name[] property.
The name can be customized by setting the configprop:management.metrics.web.server.request.metric-name[] property.
`@Timed` annotations are supported on request-handling classes and methods (see <<production-ready-metrics-timed-annotation>> for details).
`@Timed` annotations are supported on request-handling classes and methods (see <<actuator.metrics.supported.timed-annotation>> for details).
If you don't want to record metrics for all Jersey requests, you can set configprop:management.metrics.web.server.request.autotime.enabled[] to `false` and exclusively use `@Timed` annotations instead.
If you don't want to record metrics for all Jersey requests, you can set configprop:management.metrics.web.server.request.autotime.enabled[] to `false` and exclusively use `@Timed` annotations instead.
By default, Jersey server metrics are tagged with the following information:
By default, Jersey server metrics are tagged with the following information:
...
@@ -2288,7 +2288,7 @@ To customize the tags, provide a `@Bean` that implements `JerseyTagsProvider`.
...
@@ -2288,7 +2288,7 @@ To customize the tags, provide a `@Bean` that implements `JerseyTagsProvider`.
[[production-ready-metrics-http-clients]]
[[actuator.metrics.supported.http-clients]]
==== HTTP Client Metrics
==== HTTP Client Metrics
Spring Boot Actuator manages the instrumentation of both `RestTemplate` and `WebClient`.
Spring Boot Actuator manages the instrumentation of both `RestTemplate` and `WebClient`.
For that, you have to inject the auto-configured builder and use it to create instances:
For that, you have to inject the auto-configured builder and use it to create instances:
...
@@ -2328,7 +2328,7 @@ There are convenience static functions in `RestTemplateExchangeTags` and `WebCli
...
@@ -2328,7 +2328,7 @@ There are convenience static functions in `RestTemplateExchangeTags` and `WebCli
[[production-ready-metrics-tomcat]]
[[actuator.metrics.supported.tomcat]]
==== Tomcat Metrics
==== Tomcat Metrics
Auto-configuration will enable the instrumentation of Tomcat only when an `MBeanRegistry` is enabled.
Auto-configuration will enable the instrumentation of Tomcat only when an `MBeanRegistry` is enabled.
By default, the `MBeanRegistry` is disabled, but you can enable it by setting configprop:server.tomcat.mbeanregistry.enabled[] to `true`.
By default, the `MBeanRegistry` is disabled, but you can enable it by setting configprop:server.tomcat.mbeanregistry.enabled[] to `true`.
...
@@ -2337,7 +2337,7 @@ Tomcat metrics are published under the `tomcat.` meter name.
...
@@ -2337,7 +2337,7 @@ Tomcat metrics are published under the `tomcat.` meter name.
[[production-ready-metrics-cache]]
[[actuator.metrics.supported.cache]]
==== Cache Metrics
==== Cache Metrics
Auto-configuration enables the instrumentation of all available ``Cache``s on startup with metrics prefixed with `cache`.
Auto-configuration enables the instrumentation of all available ``Cache``s on startup with metrics prefixed with `cache`.
Cache instrumentation is standardized for a basic set of metrics.
Cache instrumentation is standardized for a basic set of metrics.
...
@@ -2359,7 +2359,7 @@ A `CacheMetricsRegistrar` bean is made available to make that process easier.
...
@@ -2359,7 +2359,7 @@ A `CacheMetricsRegistrar` bean is made available to make that process easier.
[[production-ready-metrics-jdbc]]
[[actuator.metrics.supported.jdbc]]
==== DataSource Metrics
==== DataSource Metrics
Auto-configuration enables the instrumentation of all available `DataSource` objects with metrics prefixed with `jdbc.connections`.
Auto-configuration enables the instrumentation of all available `DataSource` objects with metrics prefixed with `jdbc.connections`.
Data source instrumentation results in gauges representing the currently active, idle, maximum allowed, and minimum allowed connections in the pool.
Data source instrumentation results in gauges representing the currently active, idle, maximum allowed, and minimum allowed connections in the pool.
...
@@ -2374,7 +2374,7 @@ Each metric is tagged by the name of the Pool (can be controlled with `spring.da
...
@@ -2374,7 +2374,7 @@ Each metric is tagged by the name of the Pool (can be controlled with `spring.da
[[production-ready-metrics-hibernate]]
[[actuator.metrics.supported.hibernate]]
==== Hibernate Metrics
==== Hibernate Metrics
If `org.hibernate:hibernate-micrometer` is on the classpath, all available Hibernate `EntityManagerFactory` instances that have statistics enabled are instrumented with a metric named `hibernate`.
If `org.hibernate:hibernate-micrometer` is on the classpath, all available Hibernate `EntityManagerFactory` instances that have statistics enabled are instrumented with a metric named `hibernate`.
...
@@ -2393,13 +2393,13 @@ You can enable that on the auto-configured `EntityManagerFactory` as shown in th
...
@@ -2393,13 +2393,13 @@ You can enable that on the auto-configured `EntityManagerFactory` as shown in th
Auto-configuration enables the instrumentation of all Spring Data `Repository` method invocations.
Auto-configuration enables the instrumentation of all Spring Data `Repository` method invocations.
By default, metrics are generated with the name, `spring.data.repository.invocations`.
By default, metrics are generated with the name, `spring.data.repository.invocations`.
The name can be customized by setting the configprop:management.metrics.data.repository.metric-name[] property.
The name can be customized by setting the configprop:management.metrics.data.repository.metric-name[] property.
`@Timed` annotations are supported on `Repository` classes and methods (see <<production-ready-metrics-timed-annotation>> for details).
`@Timed` annotations are supported on `Repository` classes and methods (see <<actuator.metrics.supported.timed-annotation>> for details).
If you don't want to record metrics for all `Repository` invocations, you can set configprop:management.metrics.data.repository.autotime.enabled[] to `false` and exclusively use `@Timed` annotations instead.
If you don't want to record metrics for all `Repository` invocations, you can set configprop:management.metrics.data.repository.autotime.enabled[] to `false` and exclusively use `@Timed` annotations instead.
By default, repository invocation related metrics are tagged with the following information:
By default, repository invocation related metrics are tagged with the following information:
...
@@ -2424,20 +2424,20 @@ To replace the default tags, provide a `@Bean` that implements `RepositoryTagsPr
...
@@ -2424,20 +2424,20 @@ To replace the default tags, provide a `@Bean` that implements `RepositoryTagsPr
[[production-ready-metrics-rabbitmq]]
[[actuator.metrics.supported.rabbitmq]]
==== RabbitMQ Metrics
==== RabbitMQ Metrics
Auto-configuration will enable the instrumentation of all available RabbitMQ connection factories with a metric named `rabbitmq`.
Auto-configuration will enable the instrumentation of all available RabbitMQ connection factories with a metric named `rabbitmq`.
[[production-ready-metrics-integration]]
[[actuator.metrics.supported.spring-integration]]
==== Spring Integration Metrics
==== Spring Integration Metrics
Spring Integration provides {spring-integration-docs}system-management.html#micrometer-integration[Micrometer support] automatically whenever a `MeterRegistry` bean is available.
Spring Integration provides {spring-integration-docs}system-management.html#micrometer-integration[Micrometer support] automatically whenever a `MeterRegistry` bean is available.
Metrics are published under the `spring.integration.` meter name.
Metrics are published under the `spring.integration.` meter name.
[[production-ready-metrics-kafka]]
[[actuator.metrics.supported.kafka]]
==== Kafka Metrics
==== Kafka Metrics
Auto-configuration will register a `MicrometerConsumerListener` and `MicrometerProducerListener` for the auto-configured consumer factory and producer factory respectively.
Auto-configuration will register a `MicrometerConsumerListener` and `MicrometerProducerListener` for the auto-configured consumer factory and producer factory respectively.
It will also register a `KafkaStreamsMicrometerListener` for `StreamsBuilderFactoryBean`.
It will also register a `KafkaStreamsMicrometerListener` for `StreamsBuilderFactoryBean`.
...
@@ -2445,12 +2445,12 @@ For more details refer to {spring-kafka-docs}#micrometer-native[Micrometer Nativ
...
@@ -2445,12 +2445,12 @@ For more details refer to {spring-kafka-docs}#micrometer-native[Micrometer Nativ
[[production-ready-metrics-mongodb]]
[[actuator.metrics.supported.mongodb]]
==== MongoDB Metrics
==== MongoDB Metrics
[[production-ready-metrics-mongodb-command]]
[[actuator.metrics.supported.mongodb.command]]
===== Command Metrics
===== Command Metrics
Auto-configuration will register a `MongoMetricsCommandListener` with the auto-configured `MongoClient`.
Auto-configuration will register a `MongoMetricsCommandListener` with the auto-configured `MongoClient`.
...
@@ -2492,7 +2492,7 @@ To disable the auto-configured command metrics, set the following property:
...
@@ -2492,7 +2492,7 @@ To disable the auto-configured command metrics, set the following property:
In addition to `MeterFilter` beans, it's also possible to apply a limited set of customization on a per-meter basis using properties.
In addition to `MeterFilter` beans, it's also possible to apply a limited set of customization on a per-meter basis using properties.
Per-meter customizations apply to any all meter IDs that start with the given name.
Per-meter customizations apply to any all meter IDs that start with the given name.
...
@@ -2698,10 +2698,10 @@ For more details on concepts behind `percentiles-histogram`, `percentiles` and `
...
@@ -2698,10 +2698,10 @@ For more details on concepts behind `percentiles-histogram`, `percentiles` and `
[[production-ready-metrics-endpoint]]
[[actuator.metrics.endpoint]]
=== Metrics Endpoint
=== Metrics Endpoint
Spring Boot provides a `metrics` endpoint that can be used diagnostically to examine the metrics collected by an application.
Spring Boot provides a `metrics` endpoint that can be used diagnostically to examine the metrics collected by an application.
The endpoint is not available by default and must be exposed, see <<production-ready-endpoints-exposing-endpoints,exposing endpoints>> for more details.
The endpoint is not available by default and must be exposed, see <<actuator.endpoints.exposing,exposing endpoints>> for more details.
Navigating to `/actuator/metrics` displays a list of available meter names.
Navigating to `/actuator/metrics` displays a list of available meter names.
You can drill down to view information about a particular meter by providing its name as a selector, e.g. `/actuator/metrics/jvm.memory.max`.
You can drill down to view information about a particular meter by providing its name as a selector, e.g. `/actuator/metrics/jvm.memory.max`.
...
@@ -2723,7 +2723,7 @@ If you only wanted to see the maximum size for the "Metaspace", you could add an
...
@@ -2723,7 +2723,7 @@ If you only wanted to see the maximum size for the "Metaspace", you could add an
[[production-ready-auditing]]
[[actuator.auditing]]
== Auditing
== Auditing
Once Spring Security is in play, Spring Boot Actuator has a flexible audit framework that publishes events (by default, "`authentication success`", "`failure`" and "`access denied`" exceptions).
Once Spring Security is in play, Spring Boot Actuator has a flexible audit framework that publishes events (by default, "`authentication success`", "`failure`" and "`access denied`" exceptions).
This feature can be very useful for reporting and for implementing a lock-out policy based on authentication failures.
This feature can be very useful for reporting and for implementing a lock-out policy based on authentication failures.
...
@@ -2735,7 +2735,7 @@ For production environments, consider creating your own alternative `AuditEventR
...
@@ -2735,7 +2735,7 @@ For production environments, consider creating your own alternative `AuditEventR
[[production-ready-auditing-custom]]
[[actuator.auditing.custom]]
=== Custom Auditing
=== Custom Auditing
To customize published security events, you can provide your own implementations of `AbstractAuthenticationAuditListener` and `AbstractAuthorizationAuditListener`.
To customize published security events, you can provide your own implementations of `AbstractAuthenticationAuditListener` and `AbstractAuthorizationAuditListener`.
...
@@ -2744,7 +2744,7 @@ To do so, either inject the `AuditEventRepository` bean into your own components
...
@@ -2744,7 +2744,7 @@ To do so, either inject the `AuditEventRepository` bean into your own components
[[production-ready-http-tracing]]
[[actuator.tracing]]
== HTTP Tracing
== HTTP Tracing
HTTP Tracing can be enabled by providing a bean of type `HttpTraceRepository` in your application's configuration.
HTTP Tracing can be enabled by providing a bean of type `HttpTraceRepository` in your application's configuration.
For convenience, Spring Boot offers an `InMemoryHttpTraceRepository` that stores traces for the last 100 request-response exchanges, by default.
For convenience, Spring Boot offers an `InMemoryHttpTraceRepository` that stores traces for the last 100 request-response exchanges, by default.
...
@@ -2756,14 +2756,14 @@ The `httptrace` endpoint can be used to obtain information about the request-res
...
@@ -2756,14 +2756,14 @@ The `httptrace` endpoint can be used to obtain information about the request-res
[[production-ready-http-tracing-custom]]
[[actuator.tracing.custom]]
=== Custom HTTP tracing
=== Custom HTTP tracing
To customize the items that are included in each trace, use the configprop:management.trace.http.include[] configuration property.
To customize the items that are included in each trace, use the configprop:management.trace.http.include[] configuration property.
For advanced customization, consider registering your own `HttpExchangeTracer` implementation.
For advanced customization, consider registering your own `HttpExchangeTracer` implementation.
[[production-ready-process-monitoring]]
[[actuator.process-monitoring]]
== Process Monitoring
== Process Monitoring
In the `spring-boot` module, you can find two classes to create files that are often useful for process monitoring:
In the `spring-boot` module, you can find two classes to create files that are often useful for process monitoring:
...
@@ -2772,12 +2772,12 @@ In the `spring-boot` module, you can find two classes to create files that are o
...
@@ -2772,12 +2772,12 @@ In the `spring-boot` module, you can find two classes to create files that are o
By default, these writers are not activated, but you can enable:
By default, these writers are not activated, but you can enable:
You can also activate a listener by invoking the `SpringApplication.addListeners(...)` method and passing the appropriate `Writer` object.
You can also activate a listener by invoking the `SpringApplication.addListeners(...)` method and passing the appropriate `Writer` object.
This method also lets you customize the file name and path in the `Writer` constructor.
This method also lets you customize the file name and path in the `Writer` constructor.
[[production-ready-cloudfoundry]]
[[actuator.cloud-foundry]]
== Cloud Foundry Support
== Cloud Foundry Support
Spring Boot's actuator module includes additional support that is activated when you deploy to a compatible Cloud Foundry instance.
Spring Boot's actuator module includes additional support that is activated when you deploy to a compatible Cloud Foundry instance.
The `/cloudfoundryapplication` path provides an alternative secured route to all `@Endpoint` beans.
The `/cloudfoundryapplication` path provides an alternative secured route to all `@Endpoint` beans.
...
@@ -2810,7 +2810,7 @@ In order to use the endpoint, a valid UAA token must be passed with the request.
...
@@ -2810,7 +2810,7 @@ In order to use the endpoint, a valid UAA token must be passed with the request.
[[production-ready-cloudfoundry-disable]]
[[actuator.cloud-foundry.disable]]
=== Disabling Extended Cloud Foundry Actuator Support
=== Disabling Extended Cloud Foundry Actuator Support
If you want to fully disable the `/cloudfoundryapplication` endpoints, you can add the following setting to your `application.properties` file:
If you want to fully disable the `/cloudfoundryapplication` endpoints, you can add the following setting to your `application.properties` file:
...
@@ -2825,7 +2825,7 @@ If you want to fully disable the `/cloudfoundryapplication` endpoints, you can a
...
@@ -2825,7 +2825,7 @@ If you want to fully disable the `/cloudfoundryapplication` endpoints, you can a
[[production-ready-cloudfoundry-ssl]]
[[actuator.cloud-foundry.ssl]]
=== Cloud Foundry Self-signed Certificates
=== Cloud Foundry Self-signed Certificates
By default, the security verification for `/cloudfoundryapplication` endpoints makes SSL calls to various Cloud Foundry services.
By default, the security verification for `/cloudfoundryapplication` endpoints makes SSL calls to various Cloud Foundry services.
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:
...
@@ -2840,7 +2840,7 @@ If your Cloud Foundry UAA or Cloud Controller services use self-signed certifica
...
@@ -2840,7 +2840,7 @@ If your Cloud Foundry UAA or Cloud Controller services use self-signed certifica
[[production-ready-custom-context-path]]
[[actuator.cloud-foundry.custom-context-path]]
=== Custom Context Path
=== Custom Context Path
If the server's context-path has been configured to anything other than `/`, the Cloud Foundry endpoints will not be available at the root of the application.
If the server's context-path has been configured to anything other than `/`, the Cloud Foundry endpoints will not be available at the root of the application.
For example, if `server.servlet.context-path=/app`, Cloud Foundry endpoints will be available at `/app/cloudfoundryapplication/*`.
For example, if `server.servlet.context-path=/app`, Cloud Foundry endpoints will be available at `/app/cloudfoundryapplication/*`.
@@ -8,14 +8,14 @@ You can also bootstrap a new project or write your own command for it.
...
@@ -8,14 +8,14 @@ You can also bootstrap a new project or write your own command for it.
[[cli-installation]]
[[cli.installation]]
== Installing the CLI
== Installing the CLI
The Spring Boot CLI (Command-Line Interface) can be installed manually by using SDKMAN! (the SDK Manager) or by using Homebrew or MacPorts if you are an OSX user.
The Spring Boot CLI (Command-Line Interface) can be installed manually by using SDKMAN! (the SDK Manager) or by using Homebrew or MacPorts if you are an OSX user.
See _<<getting-started.adoc#getting-started-installing-the-cli>>_ in the "`Getting started`" section for comprehensive installation instructions.
See _<<getting-started.adoc#getting-started.installing.cli>>_ in the "`Getting started`" section for comprehensive installation instructions.
[[cli-using-the-cli]]
[[cli.using-the-cli]]
== Using the CLI
== Using the CLI
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:
...
@@ -66,7 +66,7 @@ The `version` command provides a quick way to check which version of Spring Boot
...
@@ -66,7 +66,7 @@ The `version` command provides a quick way to check which version of Spring Boot
[[cli-run]]
[[cli.using-the-cli.run]]
=== Running Applications with the CLI
=== Running Applications with the CLI
You can compile and run Groovy source code by using the `run` command.
You can compile and run Groovy source code by using the `run` command.
The Spring Boot CLI is completely self-contained, so you do not need any external Groovy installation.
The Spring Boot CLI is completely self-contained, so you do not need any external Groovy installation.
...
@@ -113,7 +113,7 @@ Doing so ensures the values are properly passed to the process.
...
@@ -113,7 +113,7 @@ Doing so ensures the values are properly passed to the process.
Spring Boot extends Groovy's standard `@Grab` support by letting you specify a dependency without a group or version (for example, `@Grab('freemarker')`).
Spring Boot extends Groovy's standard `@Grab` support by letting you specify a dependency without a group or version (for example, `@Grab('freemarker')`).
Doing so consults Spring Boot's default dependency metadata to deduce the artifact's group and version.
Doing so consults Spring Boot's default dependency metadata to deduce the artifact's group and version.
...
@@ -175,7 +175,7 @@ A table showing the dependencies and their versions that are included in the def
...
@@ -175,7 +175,7 @@ A table showing the dependencies and their versions that are included in the def
To help reduce the size of your Groovy code, several `import` statements are automatically included.
To help reduce the size of your Groovy code, several `import` statements are automatically included.
Notice how the preceding example refers to `@Component`, `@RestController`, and `@RequestMapping` without needing to use fully-qualified names or `import` statements.
Notice how the preceding example refers to `@Component`, `@RestController`, and `@RequestMapping` without needing to use fully-qualified names or `import` statements.
...
@@ -185,14 +185,14 @@ Try running your application to see what fails before adding imports.
...
@@ -185,14 +185,14 @@ Try running your application to see what fails before adding imports.
[[cli-automatic-main-method]]
[[cli.using-the-cli.run.automatic-main-method]]
==== Automatic Main Method
==== Automatic Main Method
Unlike the equivalent Java application, you do not need to include a `public static void main(String[] args)` method with your `Groovy` scripts.
Unlike the equivalent Java application, you do not need to include a `public static void main(String[] args)` method with your `Groovy` scripts.
A `SpringApplication` is automatically created, with your compiled code acting as the `source`.
A `SpringApplication` is automatically created, with your compiled code acting as the `source`.
By default, the CLI uses the dependency management declared in `spring-boot-dependencies` when resolving `@Grab` dependencies.
By default, the CLI uses the dependency management declared in `spring-boot-dependencies` when resolving `@Grab` dependencies.
Additional dependency management, which overrides the default dependency management, can be configured by using the `@DependencyManagementBom` annotation.
Additional dependency management, which overrides the default dependency management, can be configured by using the `@DependencyManagementBom` annotation.
...
@@ -222,7 +222,7 @@ However, to ensure consistent ordering of the dependency management, you can use
...
@@ -222,7 +222,7 @@ However, to ensure consistent ordering of the dependency management, you can use
[[cli-multiple-source-files]]
[[cli.using-the-cli.multiple-source-files]]
=== Applications with Multiple Source Files
=== Applications with Multiple Source Files
You can use "`shell globbing`" with all commands that accept file input.
You can use "`shell globbing`" with all commands that accept file input.
Doing so lets you use multiple files from a single directory, as shown in the following example:
Doing so lets you use multiple files from a single directory, as shown in the following example:
...
@@ -234,7 +234,7 @@ Doing so lets you use multiple files from a single directory, as shown in the fo
...
@@ -234,7 +234,7 @@ Doing so lets you use multiple files from a single directory, as shown in the fo
[[cli-jar]]
[[cli.using-the-cli.packaging]]
=== Packaging Your Application
=== Packaging Your Application
You can use the `jar` command to package your application into a self-contained executable jar file, as shown in the following example:
You can use the `jar` command to package your application into a self-contained executable jar file, as shown in the following example:
...
@@ -265,7 +265,7 @@ Type `spring help jar` on the command line for more information.
...
@@ -265,7 +265,7 @@ Type `spring help jar` on the command line for more information.
[[cli-init]]
[[cli.using-the-cli.initialize-new-project]]
=== Initialize a New Project
=== Initialize a New Project
The `init` command lets you create a new project by using https://start.spring.io without leaving the shell, as shown in the following example:
The `init` command lets you create a new project by using https://start.spring.io without leaving the shell, as shown in the following example:
...
@@ -317,7 +317,7 @@ For instance, the following command creates a Gradle project that uses Java 8 an
...
@@ -317,7 +317,7 @@ For instance, the following command creates a Gradle project that uses Java 8 an
[[cli-shell]]
[[cli.using-the-cli.embedded-shell]]
=== Using the Embedded Shell
=== Using the Embedded Shell
Spring Boot includes command-line completion scripts for the BASH and zsh shells.
Spring Boot includes command-line completion scripts for the BASH and zsh shells.
If you do not use either of these shells (perhaps you are a Windows user), you can use the `shell` command to launch an integrated shell, as shown in the following example:
If you do not use either of these shells (perhaps you are a Windows user), you can use the `shell` command to launch an integrated shell, as shown in the following example:
...
@@ -343,7 +343,7 @@ To exit the embedded shell, press `ctrl-c`.
...
@@ -343,7 +343,7 @@ To exit the embedded shell, press `ctrl-c`.
[[cli-install-uninstall]]
[[cli.using-the-cli.extensions]]
=== Adding Extensions to the CLI
=== Adding Extensions to the CLI
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:
...
@@ -374,7 +374,7 @@ To uninstall all additional dependencies, you can use the `--all` option, as sho
...
@@ -374,7 +374,7 @@ To uninstall all additional dependencies, you can use the `--all` option, as sho
[[cli-groovy-beans-dsl]]
[[cli.groovy-beans-dsl]]
== Developing Applications with the Groovy Beans DSL
== Developing Applications with the Groovy Beans DSL
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:
...
@@ -407,7 +407,7 @@ You can mix class declarations with `beans{}` in the same file as long as they s
...
@@ -407,7 +407,7 @@ You can mix class declarations with `beans{}` in the same file as long as they s
[[cli-maven-settings]]
[[cli.maven-setting]]
== Configuring the CLI with settings.xml
== Configuring the CLI with settings.xml
The Spring Boot CLI uses Aether, Maven's dependency resolution engine, to resolve dependencies.
The Spring Boot CLI uses Aether, Maven's dependency resolution engine, to resolve dependencies.
The CLI makes use of the Maven configuration found in `~/.m2/settings.xml` to configure Aether.
The CLI makes use of the Maven configuration found in `~/.m2/settings.xml` to configure Aether.
...
@@ -426,7 +426,7 @@ See https://maven.apache.org/settings.html[Maven's settings documentation] for f
...
@@ -426,7 +426,7 @@ See https://maven.apache.org/settings.html[Maven's settings documentation] for f
[[cli-whats-next]]
[[cli.whats-next]]
== What to Read Next
== What to Read Next
There are some {spring-boot-code}/spring-boot-project/spring-boot-cli/samples[sample groovy scripts] available from the GitHub repository that you can use to try out the Spring Boot CLI.
There are some {spring-boot-code}/spring-boot-project/spring-boot-cli/samples[sample groovy scripts] available from the GitHub repository that you can use to try out the Spring Boot CLI.
There is also extensive Javadoc throughout the {spring-boot-cli-module-code}[source code].
There is also extensive Javadoc throughout the {spring-boot-cli-module-code}[source code].
@@ -11,15 +11,15 @@ If you are starting out with Spring Boot, you should probably read the _<<gettin
...
@@ -11,15 +11,15 @@ If you are starting out with Spring Boot, you should probably read the _<<gettin
[[using-boot-build-systems]]
[[using.build-systems]]
== Build Systems
== Build Systems
It is strongly recommended that you choose a build system that supports <<using-boot-dependency-management,_dependency management_>> and that can consume artifacts published to the "`Maven Central`" repository.
It is strongly recommended that you choose a build system that supports <<using.build-systems.dependency-management,_dependency management_>> and that can consume artifacts published to the "`Maven Central`" repository.
We would recommend that you choose Maven or Gradle.
We would recommend that you choose Maven or Gradle.
It is possible to get Spring Boot to work with other build systems (Ant, for example), but they are not particularly well supported.
It is possible to get Spring Boot to work with other build systems (Ant, for example), but they are not particularly well supported.
[[using-boot-dependency-management]]
[[using.build-systems.dependency-management]]
=== Dependency Management
=== Dependency Management
Each release of Spring Boot provides a curated list of dependencies that it supports.
Each release of Spring Boot provides a curated list of dependencies that it supports.
In practice, you do not need to provide a version for any of these dependencies in your build configuration, as Spring Boot manages that for you.
In practice, you do not need to provide a version for any of these dependencies in your build configuration, as Spring Boot manages that for you.
...
@@ -28,14 +28,14 @@ When you upgrade Spring Boot itself, these dependencies are upgraded as well in
...
@@ -28,14 +28,14 @@ When you upgrade Spring Boot itself, these dependencies are upgraded as well in
NOTE: You can still specify a version and override Spring Boot's recommendations if you need to do so.
NOTE: You can still specify a version and override Spring Boot's recommendations if you need to do so.
The curated list contains all the Spring modules that you can use with Spring Boot as well as a refined list of third party libraries.
The curated list contains all the Spring modules that you can use with Spring Boot as well as a refined list of third party libraries.
The list is available as a standard Bills of Materials (`spring-boot-dependencies`) that can be used with both <<using-boot-maven,Maven>> and <<using-boot-gradle,Gradle>>.
The list is available as a standard Bills of Materials (`spring-boot-dependencies`) that can be used with both <<using.build-systems.maven,Maven>> and <<using.build-systems.gradle,Gradle>>.
WARNING: Each release of Spring Boot is associated with a base version of the Spring Framework.
WARNING: Each release of Spring Boot is associated with a base version of the Spring Framework.
We **highly** recommend that you not specify its version.
We **highly** recommend that you not specify its version.
[[using-boot-maven]]
[[using.build-systems.maven]]
=== Maven
=== Maven
To learn about using Spring Boot with Maven, please refer to the documentation for Spring Boot's Maven plugin:
To learn about using Spring Boot with Maven, please refer to the documentation for Spring Boot's Maven plugin:
...
@@ -44,7 +44,7 @@ To learn about using Spring Boot with Maven, please refer to the documentation f
...
@@ -44,7 +44,7 @@ To learn about using Spring Boot with Maven, please refer to the documentation f
[[using-boot-gradle]]
[[using.build-systems.gradle]]
=== Gradle
=== Gradle
To learn about using Spring Boot with Gradle, please refer to the documentation for Spring Boot's Gradle plugin:
To learn about using Spring Boot with Gradle, please refer to the documentation for Spring Boot's Gradle plugin:
...
@@ -53,7 +53,7 @@ To learn about using Spring Boot with Gradle, please refer to the documentation
...
@@ -53,7 +53,7 @@ To learn about using Spring Boot with Gradle, please refer to the documentation
[[using-boot-ant]]
[[using.build-systems.ant]]
=== Ant
=== Ant
It is possible to build a Spring Boot project using Apache Ant+Ivy.
It is possible to build a Spring Boot project using Apache Ant+Ivy.
The `spring-boot-antlib` "`AntLib`" module is also available to help Ant create executable jars.
The `spring-boot-antlib` "`AntLib`" module is also available to help Ant create executable jars.
...
@@ -114,11 +114,11 @@ A typical `build.xml` looks like the following example:
...
@@ -114,11 +114,11 @@ A typical `build.xml` looks like the following example:
</project>
</project>
----
----
TIP: If you do not want to use the `spring-boot-antlib` module, see the _<<howto.adoc#howto-build-an-executable-archive-with-ant>>_ "`How-to`" .
TIP: If you do not want to use the `spring-boot-antlib` module, see the _<<howto.adoc#howto.build.build-an-executable-archive-with-ant-without-using-spring-boot-antlib>>_ "`How-to`" .
[[using-boot-starter]]
[[using.build-systems.starters]]
=== Starters
=== Starters
Starters are a set of convenient dependency descriptors that you can include in your application.
Starters are a set of convenient dependency descriptors that you can include in your application.
You get a one-stop shop for all the Spring and related technologies that you need without having to hunt through sample code and copy-paste loads of dependency descriptors.
You get a one-stop shop for all the Spring and related technologies that you need without having to hunt through sample code and copy-paste loads of dependency descriptors.
...
@@ -133,7 +133,7 @@ This naming structure is intended to help when you need to find a starter.
...
@@ -133,7 +133,7 @@ This naming structure is intended to help when you need to find a starter.
The Maven integration in many IDEs lets you search dependencies by name.
The Maven integration in many IDEs lets you search dependencies by name.
For example, with the appropriate Eclipse or STS plugin installed, you can press `ctrl-space` in the POM editor and type "`spring-boot-starter`" for a complete list.
For example, with the appropriate Eclipse or STS plugin installed, you can press `ctrl-space` in the POM editor and type "`spring-boot-starter`" for a complete list.
As explained in the "`<<spring-boot-features#boot-features-custom-starter,Creating Your Own Starter>>`" section, third party starters should not start with `spring-boot`, as it is reserved for official Spring Boot artifacts.
As explained in the "`<<spring-boot-features#features.developing-auto-configuration.custom-starter,Creating Your Own Starter>>`" section, third party starters should not start with `spring-boot`, as it is reserved for official Spring Boot artifacts.
Rather, a third-party starter typically starts with the name of the project.
Rather, a third-party starter typically starts with the name of the project.
For example, a third-party starter project called `thirdpartyproject` would typically be named `thirdpartyproject-spring-boot-starter`.
For example, a third-party starter project called `thirdpartyproject` would typically be named `thirdpartyproject-spring-boot-starter`.
****
****
...
@@ -143,7 +143,7 @@ The following application starters are provided by Spring Boot under the `org.sp
...
@@ -143,7 +143,7 @@ The following application starters are provided by Spring Boot under the `org.sp
.Spring Boot application starters
.Spring Boot application starters
include::starters/application-starters.adoc[]
include::starters/application-starters.adoc[]
In addition to the application starters, the following starters can be used to add _<<production-ready-features.adoc#production-ready, production ready>>_ features:
In addition to the application starters, the following starters can be used to add _<<production-ready-features.adoc#actuator, production ready>>_ features:
.Spring Boot production starters
.Spring Boot production starters
include::starters/production-starters.adoc[]
include::starters/production-starters.adoc[]
...
@@ -153,20 +153,20 @@ Finally, Spring Boot also includes the following starters that can be used if yo
...
@@ -153,20 +153,20 @@ Finally, Spring Boot also includes the following starters that can be used if yo
.Spring Boot technical starters
.Spring Boot technical starters
include::starters/technical-starters.adoc[]
include::starters/technical-starters.adoc[]
To learn how to swap technical facets, please see the how-to documentation for <<howto.adoc#howto-use-another-web-server, swapping web server>> and <<howto.adoc#howto-configure-log4j-for-logging, logging system>>.
To learn how to swap technical facets, please see the how-to documentation for <<howto.adoc#howto.webserver.use-another, swapping web server>> and <<howto.adoc#howto.logging.log4j, logging system>>.
TIP: For a list of additional community contributed starters, see the {spring-boot-latest-code}/spring-boot-project/spring-boot-starters/README.adoc[README file] in the `spring-boot-starters` module on GitHub.
TIP: For a list of additional community contributed starters, see the {spring-boot-latest-code}/spring-boot-project/spring-boot-starters/README.adoc[README file] in the `spring-boot-starters` module on GitHub.
[[using-boot-structuring-your-code]]
[[using.structuring-your-code]]
== Structuring Your Code
== Structuring Your Code
Spring Boot does not require any specific code layout to work.
Spring Boot does not require any specific code layout to work.
We generally recommend that you locate your main application class in a root package above other classes.
We generally recommend that you locate your main application class in a root package above other classes.
The <<using-boot-using-springbootapplication-annotation, `@SpringBootApplication` annotation>> is often placed on your main class, and it implicitly defines a base "`search package`" for certain items.
The <<using.using-the-springbootapplication-annotation, `@SpringBootApplication` annotation>> is often placed on your main class, and it implicitly defines a base "`search package`" for certain items.
For example, if you are writing a JPA application, the package of the `@SpringBootApplication` annotated class is used to search for `@Entity` items.
For example, if you are writing a JPA application, the package of the `@SpringBootApplication` annotated class is used to search for `@Entity` items.
Using a root package also allows component scan to apply only on your project.
Using a root package also allows component scan to apply only on your project.
...
@@ -228,7 +228,7 @@ The `Application.java` file would declare the `main` method, along with the basi
...
@@ -228,7 +228,7 @@ The `Application.java` file would declare the `main` method, along with the basi
[[using-boot-configuration-classes]]
[[using.configuration-classes]]
== Configuration Classes
== Configuration Classes
Spring Boot favors Java-based configuration.
Spring Boot favors Java-based configuration.
Although it is possible to use `SpringApplication` with XML sources, we generally recommend that your primary source be a single `@Configuration` class.
Although it is possible to use `SpringApplication` with XML sources, we generally recommend that your primary source be a single `@Configuration` class.
...
@@ -240,7 +240,7 @@ Searching for `+Enable*+` annotations can be a good starting point.
...
@@ -240,7 +240,7 @@ Searching for `+Enable*+` annotations can be a good starting point.
If you absolutely must use XML based configuration, we recommend that you still start with a `@Configuration` class.
If you absolutely must use XML based configuration, we recommend that you still start with a `@Configuration` class.
You can then use an `@ImportResource` annotation to load XML configuration files.
You can then use an `@ImportResource` annotation to load XML configuration files.
[[using-boot-auto-configuration]]
[[using.auto-configuration]]
== Auto-configuration
== Auto-configuration
Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added.
Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added.
For example, if `HSQLDB` is on your classpath, and you have not manually configured any database connection beans, then Spring Boot auto-configures an in-memory database.
For example, if `HSQLDB` is on your classpath, and you have not manually configured any database connection beans, then Spring Boot auto-configures an in-memory database.
...
@@ -267,7 +267,7 @@ We generally recommend that you add one or the other to your primary `@Configura
...
@@ -267,7 +267,7 @@ We generally recommend that you add one or the other to your primary `@Configura
[[using-boot-replacing-auto-configuration]]
[[using.auto-configuration.replacing]]
=== Gradually Replacing Auto-configuration
=== Gradually Replacing Auto-configuration
Auto-configuration is non-invasive.
Auto-configuration is non-invasive.
At any point, you can start to define your own configuration to replace specific parts of the auto-configuration.
At any point, you can start to define your own configuration to replace specific parts of the auto-configuration.
...
@@ -278,7 +278,7 @@ Doing so enables debug logs for a selection of core loggers and logs a condition
...
@@ -278,7 +278,7 @@ Doing so enables debug logs for a selection of core loggers and logs a condition
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:
...
@@ -303,7 +303,7 @@ The actual contents of those classes, such as nested configuration classes or be
...
@@ -303,7 +303,7 @@ The actual contents of those classes, such as nested configuration classes or be
Many Spring Boot developers like their apps to use auto-configuration, component scan and be able to define extra configuration on their "application class".
Many Spring Boot developers like their apps to use auto-configuration, component scan and be able to define extra configuration on their "application class".
A single `@SpringBootApplication` annotation can be used to enable those three features, that is:
A single `@SpringBootApplication` annotation can be used to enable those three features, that is:
* `@ComponentScan`: enable `@Component` scan on the package where the application is located (see <<using-boot-structuring-your-code,the best practices>>)
* `@ComponentScan`: enable `@Component` scan on the package where the application is located (see <<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,pending-extract=true,indent=0]
[source,java,pending-extract=true,indent=0]
...
@@ -416,7 +416,7 @@ In this example, `Application` is just like any other Spring Boot application ex
...
@@ -416,7 +416,7 @@ In this example, `Application` is just like any other Spring Boot application ex
[[using-boot-running-your-application]]
[[using.running-your-application]]
== Running Your Application
== Running Your Application
One of the biggest advantages of packaging your application as a jar and using an embedded HTTP server is that you can run your application as you would any other.
One of the biggest advantages of packaging your application as a jar and using an embedded HTTP server is that you can run your application as you would any other.
The sample applies to debugging Spring Boot applications.
The sample applies to debugging Spring Boot applications.
...
@@ -427,7 +427,7 @@ If you choose to package your application as a war file, you should refer to you
...
@@ -427,7 +427,7 @@ If you choose to package your application as a war file, you should refer to you
[[using-boot-running-from-an-ide]]
[[using.running-your-application.from-an-ide]]
=== Running from an IDE
=== Running from an IDE
You can run a Spring Boot application from your IDE as a Java application.
You can run a Spring Boot application from your IDE as a Java application.
However, you first need to import your project.
However, you first need to import your project.
...
@@ -444,7 +444,7 @@ STS users can use the `Relaunch` button rather than the `Run` button to ensure t
...
@@ -444,7 +444,7 @@ STS users can use the `Relaunch` button rather than the `Run` button to ensure t
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:
...
@@ -464,7 +464,7 @@ Doing so lets you attach a debugger to your packaged application, as shown in th
...
@@ -464,7 +464,7 @@ Doing so lets you attach a debugger to your packaged application, as shown in th
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:
...
@@ -503,18 +503,18 @@ You might also want to use the `JAVA_OPTS` operating system environment variable
...
@@ -503,18 +503,18 @@ You might also want to use the `JAVA_OPTS` operating system environment variable
[[using-boot-hot-swapping]]
[[using.running-your-application.hot-swapping]]
=== Hot Swapping
=== Hot Swapping
Since Spring Boot applications are plain Java applications, JVM hot-swapping should work out of the box.
Since Spring Boot applications are plain Java applications, JVM hot-swapping should work out of the box.
JVM hot swapping is somewhat limited with the bytecode that it can replace.
JVM hot swapping is somewhat limited with the bytecode that it can replace.
For a more complete solution, https://www.jrebel.com/products/jrebel[JRebel] can be used.
For a more complete solution, https://www.jrebel.com/products/jrebel[JRebel] can be used.
The `spring-boot-devtools` module also includes support for quick application restarts.
The `spring-boot-devtools` module also includes support for quick application restarts.
See the <<using-boot-devtools>> section later in this chapter and the <<howto.adoc#howto-hotswapping, Hot swapping "`How-to`">> for details.
See the <<using.devtools>> section later in this chapter and the <<howto.adoc#howto.hotswapping, Hot swapping "`How-to`">> for details.
[[using-boot-devtools]]
[[using.devtools]]
== Developer Tools
== Developer Tools
Spring Boot includes an additional set of tools that can make the application development experience a little more pleasant.
Spring Boot includes an additional set of tools that can make the application development experience a little more pleasant.
The `spring-boot-devtools` module can be included in any project to provide additional development-time features.
The `spring-boot-devtools` module can be included in any project to provide additional development-time features.
...
@@ -550,16 +550,16 @@ To disable devtools, exclude the dependency or set the `-Dspring.devtools.restar
...
@@ -550,16 +550,16 @@ To disable devtools, exclude the dependency or set the `-Dspring.devtools.restar
TIP: Flagging the dependency as optional in Maven or using the `developmentOnly` configuration in Gradle (as shown above) prevents devtools from being transitively applied to other modules that use your project.
TIP: Flagging the dependency as optional in Maven or using the `developmentOnly` configuration in Gradle (as shown above) prevents devtools from being transitively applied to other modules that use your project.
TIP: Repackaged archives do not contain devtools by default.
TIP: Repackaged archives do not contain devtools by default.
If you want to use a <<using-boot-devtools-remote,certain remote devtools feature>>, you need to include it.
If you want to use a <<using.devtools.remote-applications,certain remote devtools feature>>, you need to include it.
When using the Maven plugin, set the `excludeDevtools` property to `false`.
When using the Maven plugin, set the `excludeDevtools` property to `false`.
When using the Gradle plugin, {spring-boot-gradle-plugin-docs}#packaging-executable-configuring-including-development-only-dependencies[configure the task's classpath to include the `developmentOnly` configuration].
When using the Gradle plugin, {spring-boot-gradle-plugin-docs}#packaging-executable-configuring-including-development-only-dependencies[configure the task's classpath to include the `developmentOnly` configuration].
[[using-boot-devtools-property-defaults]]
[[using.devtools.property-defaults]]
=== Property Defaults
=== Property Defaults
Several of the libraries supported by Spring Boot use caches to improve performance.
Several of the libraries supported by Spring Boot use caches to improve performance.
For example, <<spring-boot-features#boot-features-spring-mvc-template-engines,template engines>> cache compiled templates to avoid repeatedly parsing template files.
For example, <<spring-boot-features#features.developing-web-applications.spring-mvc.template-engines,template engines>> cache compiled templates to avoid repeatedly parsing template files.
Also, Spring MVC can add HTTP caching headers to responses when serving static resources.
Also, Spring MVC can add HTTP caching headers to responses when serving static resources.
While caching is very beneficial in production, it can be counter-productive during development, preventing you from seeing the changes you just made in your application.
While caching is very beneficial in production, it can be counter-productive during development, preventing you from seeing the changes you just made in your application.
...
@@ -579,12 +579,12 @@ TIP: For a complete list of the properties that are applied by the devtools, see
...
@@ -579,12 +579,12 @@ TIP: For a complete list of the properties that are applied by the devtools, see
[[using-boot-devtools-restart]]
[[using.devtools.restart]]
=== Automatic Restart
=== Automatic Restart
Applications that use `spring-boot-devtools` automatically restart whenever files on the classpath change.
Applications that use `spring-boot-devtools` automatically restart whenever files on the classpath change.
This can be a useful feature when working in an IDE, as it gives a very fast feedback loop for code changes.
This can be a useful feature when working in an IDE, as it gives a very fast feedback loop for code changes.
By default, any entry on the classpath that points to a directory is monitored for changes.
By default, any entry on the classpath that points to a directory is monitored for changes.
Note that certain resources, such as static assets and view templates, <<using-boot-devtools-restart-exclude, do not need to restart the application>>.
Note that certain resources, such as static assets and view templates, <<using.devtools.restart.excluding-resources, do not need to restart the application>>.
.Triggering a restart
.Triggering a restart
****
****
...
@@ -600,7 +600,7 @@ NOTE: If you are restarting with Maven or Gradle using the build plugin you must
...
@@ -600,7 +600,7 @@ NOTE: If you are restarting with Maven or Gradle using the build plugin you must
If you disable forking, the isolated application classloader used by devtools will not be created and restarts will not operate properly.
If you disable forking, the isolated application classloader used by devtools will not be created and restarts will not operate properly.
TIP: Automatic restart works very well when used with LiveReload.
TIP: Automatic restart works very well when used with LiveReload.
<<using-boot-devtools-livereload,See the LiveReload section>> for details.
<<using.devtools.livereload,See the LiveReload section>> for details.
If you use JRebel, automatic restarts are disabled in favor of dynamic class reloading.
If you use JRebel, automatic restarts are disabled in favor of dynamic class reloading.
Other devtools features (such as LiveReload and property overrides) can still be used.
Other devtools features (such as LiveReload and property overrides) can still be used.
...
@@ -626,7 +626,7 @@ These work by rewriting classes as they are loaded to make them more amenable to
...
@@ -626,7 +626,7 @@ These work by rewriting classes as they are loaded to make them more amenable to
By default, each time your application restarts, a report showing the condition evaluation delta is logged.
By default, each time your application restarts, a report showing the condition evaluation delta is logged.
The report shows the changes to your application's auto-configuration as you make changes such as adding or removing beans and setting configuration properties.
The report shows the changes to your application's auto-configuration as you make changes such as adding or removing beans and setting configuration properties.
...
@@ -643,11 +643,11 @@ To disable the logging of the report, set the following property:
...
@@ -643,11 +643,11 @@ To disable the logging of the report, set the following property:
[[using-boot-devtools-restart-exclude]]
[[using.devtools.restart.excluding-resources]]
==== Excluding Resources
==== Excluding Resources
Certain resources do not necessarily need to trigger a restart when they are changed.
Certain resources do not necessarily need to trigger a restart when they are changed.
For example, Thymeleaf templates can be edited in-place.
For example, Thymeleaf templates can be edited in-place.
By default, changing resources in `/META-INF/maven`, `/META-INF/resources`, `/resources`, `/static`, `/public`, or `/templates` does not trigger a restart but does trigger a <<using-boot-devtools-livereload, live reload>>.
By default, changing resources in `/META-INF/maven`, `/META-INF/resources`, `/resources`, `/static`, `/public`, or `/templates` does not trigger a restart but does trigger a <<using.devtools.livereload, live reload>>.
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:
...
@@ -663,15 +663,15 @@ TIP: If you want to keep those defaults and _add_ additional exclusions, use the
...
@@ -663,15 +663,15 @@ TIP: If you want to keep those defaults and _add_ additional exclusions, use the
You may want your application to be restarted or reloaded when you make changes to files that are not on the classpath.
You may want your application to be restarted or reloaded when you make changes to files that are not on the classpath.
To do so, use the configprop:spring.devtools.restart.additional-paths[] property to configure additional paths to watch for changes.
To do so, use the configprop:spring.devtools.restart.additional-paths[] property to configure additional paths to watch for changes.
You can use the configprop:spring.devtools.restart.exclude[] property <<using-boot-devtools-restart-exclude, described earlier>> to control whether changes beneath the additional paths trigger a full restart or a <<using-boot-devtools-livereload, live reload>>.
You can use the configprop:spring.devtools.restart.exclude[] property <<using.devtools.restart.excluding-resources, described earlier>> to control whether changes beneath the additional paths trigger a full restart or a <<using.devtools.livereload, live reload>>.
[[using-boot-devtools-restart-disable]]
[[using.devtools.restart.disable]]
==== Disabling Restart
==== Disabling Restart
If you do not want to use the restart feature, you can disable it by using the configprop:spring.devtools.restart.enabled[] property.
If you do not want to use the restart feature, you can disable it by using the configprop:spring.devtools.restart.enabled[] property.
In most cases, you can set this property in your `application.properties` (doing so still initializes the restart classloader, but it does not watch for file changes).
In most cases, you can set this property in your `application.properties` (doing so still initializes the restart classloader, but it does not watch for file changes).
...
@@ -688,7 +688,7 @@ If you need to _completely_ disable restart support (for example, because it doe
...
@@ -688,7 +688,7 @@ If you need to _completely_ disable restart support (for example, because it doe
[[using-boot-devtools-restart-triggerfile]]
[[using.devtools.restart.triggerfile]]
==== Using a Trigger File
==== Using a Trigger File
If you work with an IDE that continuously compiles changed files, you might prefer to trigger restarts only at specific times.
If you work with an IDE that continuously compiles changed files, you might prefer to trigger restarts only at specific times.
To do so, you can use a "`trigger file`", which is a special file that must be modified when you want to actually trigger a restart check.
To do so, you can use a "`trigger file`", which is a special file that must be modified when you want to actually trigger a restart check.
...
@@ -720,7 +720,7 @@ Then your `trigger-file` property would be:
...
@@ -720,7 +720,7 @@ Then your `trigger-file` property would be:
Restarts will now only happen when the `src/main/resources/.reloadtrigger` is updated.
Restarts will now only happen when the `src/main/resources/.reloadtrigger` is updated.
TIP: You might want to set `spring.devtools.restart.trigger-file` as a <<using-boot-devtools-globalsettings,global setting>>, so that all your projects behave in the same way.
TIP: You might want to set `spring.devtools.restart.trigger-file` as a <<using.devtools.globalsettings,global setting>>, so that all your projects behave in the same way.
Some IDEs have features that save you from needing to update your trigger file manually.
Some IDEs have features that save you from needing to update your trigger file manually.
https://spring.io/tools[Spring Tools for Eclipse] and https://www.jetbrains.com/idea/[IntelliJ IDEA (Ultimate Edition)] both have such support.
https://spring.io/tools[Spring Tools for Eclipse] and https://www.jetbrains.com/idea/[IntelliJ IDEA (Ultimate Edition)] both have such support.
...
@@ -729,7 +729,7 @@ For IntelliJ IDEA, you can follow the https://www.jetbrains.com/help/idea/spring
...
@@ -729,7 +729,7 @@ For IntelliJ IDEA, you can follow the https://www.jetbrains.com/help/idea/spring
As described earlier in the <<using-spring-boot-restart-vs-reload>> section, restart functionality is implemented by using two classloaders.
As described earlier in the <<using-spring-boot-restart-vs-reload>> section, restart functionality is implemented by using two classloaders.
For most applications, this approach works well.
For most applications, this approach works well.
...
@@ -760,7 +760,7 @@ You can package files inside your project, or in the libraries that the project
...
@@ -760,7 +760,7 @@ You can package files inside your project, or in the libraries that the project
[[using-boot-devtools-known-restart-limitations]]
[[using.devtools.restart.limitations]]
==== Known Limitations
==== Known Limitations
Restart functionality does not work well with objects that are deserialized by using a standard `ObjectInputStream`.
Restart functionality does not work well with objects that are deserialized by using a standard `ObjectInputStream`.
If you need to deserialize data, you may need to use Spring's `ConfigurableObjectInputStream` in combination with `Thread.currentThread().getContextClassLoader()`.
If you need to deserialize data, you may need to use Spring's `ConfigurableObjectInputStream` in combination with `Thread.currentThread().getContextClassLoader()`.
...
@@ -770,7 +770,7 @@ If you find such a problem, you need to request a fix with the original authors.
...
@@ -770,7 +770,7 @@ If you find such a problem, you need to request a fix with the original authors.
[[using-boot-devtools-livereload]]
[[using.devtools.livereload]]
=== LiveReload
=== LiveReload
The `spring-boot-devtools` module includes an embedded LiveReload server that can be used to trigger a browser refresh when a resource is changed.
The `spring-boot-devtools` module includes an embedded LiveReload server that can be used to trigger a browser refresh when a resource is changed.
LiveReload browser extensions are freely available for Chrome, Firefox and Safari from http://livereload.com/extensions/[livereload.com].
LiveReload browser extensions are freely available for Chrome, Firefox and Safari from http://livereload.com/extensions/[livereload.com].
...
@@ -781,11 +781,11 @@ NOTE: You can only run one LiveReload server at a time.
...
@@ -781,11 +781,11 @@ NOTE: You can only run one LiveReload server at a time.
Before starting your application, ensure that no other LiveReload servers are running.
Before starting your application, ensure that no other LiveReload servers are running.
If you start multiple applications from your IDE, only the first has LiveReload support.
If you start multiple applications from your IDE, only the first has LiveReload support.
WARNING: To trigger LiveReload when a file changes, <<using-boot-devtools-restart>> must be enabled.
WARNING: To trigger LiveReload when a file changes, <<using.devtools.restart>> must be enabled.
[[using-boot-devtools-globalsettings]]
[[using.devtools.globalsettings]]
=== Global Settings
=== Global Settings
You can configure global devtools settings by adding any of the following files to the `$HOME/.config/spring-boot` directory:
You can configure global devtools settings by adding any of the following files to the `$HOME/.config/spring-boot` directory:
...
@@ -794,7 +794,7 @@ You can configure global devtools settings by adding any of the following files
...
@@ -794,7 +794,7 @@ You can configure global devtools settings by adding any of the following files
. `spring-boot-devtools.yml`
. `spring-boot-devtools.yml`
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-boot-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.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,configprops,configblocks]
----
----
...
@@ -811,13 +811,13 @@ This allows you to share the devtools global configuration with applications tha
...
@@ -811,13 +811,13 @@ This allows you to share the devtools global configuration with applications tha
====
====
Profiles are not supported in devtools properties/yaml files.
Profiles are not supported in devtools properties/yaml files.
Any profiles activated in `.spring-boot-devtools.properties` will not affect the loading of <<spring-boot-features.adoc#boot-features-external-config-files-profile-specific, profile-specific configuration files>>.
Any profiles activated in `.spring-boot-devtools.properties` will not affect the loading of <<spring-boot-features.adoc#features.external-config.files.profile-specific, profile-specific configuration files>>.
Profile specific filenames (of the form `spring-boot-devtools-<profile>.properties`) and `spring.config.activate.on-profile` documents in both YAML and Properties files are not supported.
Profile specific filenames (of the form `spring-boot-devtools-<profile>.properties`) and `spring.config.activate.on-profile` documents in both YAML and Properties files are not supported.
{spring-boot-devtools-module-code}/filewatch/FileSystemWatcher.java[FileSystemWatcher] works by polling the class changes with a certain time interval, and then waiting for a predefined quiet period to make sure there are no more changes.
{spring-boot-devtools-module-code}/filewatch/FileSystemWatcher.java[FileSystemWatcher] works by polling the class changes with a certain time interval, and then waiting for a predefined quiet period to make sure there are no more changes.
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.
...
@@ -836,7 +836,7 @@ The monitored classpath directories are now polled every 2 seconds for changes,
...
@@ -836,7 +836,7 @@ The monitored classpath directories are now polled every 2 seconds for changes,
[[using-boot-devtools-remote]]
[[using.devtools.remote-applications]]
=== Remote Applications
=== Remote Applications
The Spring Boot developer tools are not limited to local development.
The Spring Boot developer tools are not limited to local development.
You can also use several features when running applications remotely.
You can also use several features when running applications remotely.
...
@@ -871,7 +871,7 @@ The client component must be launched manually.
...
@@ -871,7 +871,7 @@ The client component must be launched manually.
[[running-remote-client-application]]
[[using.devtools.remote-applications.client]]
==== Running the Remote Client Application
==== Running the Remote Client Application
The remote client application is designed to be run from within your IDE.
The remote client application is designed to be run from within your IDE.
You need to run `org.springframework.boot.devtools.RemoteSpringApplication` with the same classpath as the remote project that you connect to.
You need to run `org.springframework.boot.devtools.RemoteSpringApplication` with the same classpath as the remote project that you connect to.
...
@@ -913,9 +913,9 @@ TIP: If you need to use a proxy to access the remote application, configure the
...
@@ -913,9 +913,9 @@ TIP: If you need to use a proxy to access the remote application, configure the
[[using-boot-devtools-remote-update]]
[[using.devtools.remote-applications.update]]
==== Remote Update
==== Remote Update
The remote client monitors your application classpath for changes in the same way as the <<using-boot-devtools-restart,local restart>>.
The remote client monitors your application classpath for changes in the same way as the <<using.devtools.restart,local restart>>.
Any updated resource is pushed to the remote application and (_if required_) triggers a restart.
Any updated resource is pushed to the remote application and (_if required_) triggers a restart.
This can be helpful if you iterate on a feature that uses a cloud service that you do not have locally.
This can be helpful if you iterate on a feature that uses a cloud service that you do not have locally.
Generally, remote updates and restarts are much quicker than a full rebuild and deploy cycle.
Generally, remote updates and restarts are much quicker than a full rebuild and deploy cycle.
...
@@ -927,24 +927,24 @@ The next batch can’t be sent to the application, since the server is restartin
...
@@ -927,24 +927,24 @@ The next batch can’t be sent to the application, since the server is restartin
This is typically manifested by a warning in the `RemoteSpringApplication` logs about failing to upload some of the classes, and a consequent retry.
This is typically manifested by a warning in the `RemoteSpringApplication` logs about failing to upload some of the classes, and a consequent retry.
But it may also lead to application code inconsistency and failure to restart after the first batch of changes is uploaded.
But it may also lead to application code inconsistency and failure to restart after the first batch of changes is uploaded.
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.
See the <<configuring-file-system-watcher>> section for configuring these properties.
See the <<using.devtools.globalsettings.configuring-file-system-watcher>> section for configuring these properties.
NOTE: Files are only monitored when the remote client is running.
NOTE: Files are only monitored when the remote client is running.
If you change a file before starting the remote client, it is not pushed to the remote server.
If you change a file before starting the remote client, it is not pushed to the remote server.
[[using-boot-packaging-for-production]]
[[using.packaging-for-production]]
== Packaging Your Application for Production
== Packaging Your Application for Production
Executable jars can be used for production deployment.
Executable jars can be used for production deployment.
As they are self-contained, they are also ideally suited for cloud-based deployment.
As they are self-contained, they are also ideally suited for cloud-based deployment.
For additional "`production ready`" features, such as health, auditing, and metric REST or JMX end-points, consider adding `spring-boot-actuator`.
For additional "`production ready`" features, such as health, auditing, and metric REST or JMX end-points, consider adding `spring-boot-actuator`.
See _<<production-ready-features.adoc#production-ready>>_ for details.
See _<<production-ready-features.adoc#actuator>>_ for details.
[[using-boot-whats-next]]
[[using.whats-next]]
== What to Read Next
== What to Read Next
You should now understand how you can use Spring Boot and some best practices that you should follow.
You should now understand how you can use Spring Boot and some best practices that you should follow.
You can now go on to learn about specific _<<spring-boot-features#boot-features, Spring Boot features>>_ in depth, or you could skip ahead and read about the "`<<production-ready-features#production-ready, production ready>>`" aspects of Spring Boot.
You can now go on to learn about specific _<<spring-boot-features#features, Spring Boot features>>_ in depth, or you could skip ahead and read about the "`<<production-ready-features#actuator, production ready>>`" aspects of Spring Boot.