Application Information
Application information exposes various information collected from all InfoContributor
beans defined in your ApplicationContext
.
Spring Boot includes a number of auto-configured InfoContributor
beans, and you can write your own.
Auto-configured InfoContributors
When appropriate, Spring auto-configures the following InfoContributor
beans:
ID | Name | Description | Prerequisites |
---|---|---|---|
|
Exposes build information. |
A |
|
|
Exposes any property from the |
None. |
|
|
Exposes git information. |
A |
|
|
Exposes Java runtime information. |
None. |
|
|
Exposes Operating System information. |
None. |
Whether an individual contributor is enabled is controlled by its management.info.<id>.enabled
property.
Different contributors have different defaults for this property, depending on their prerequisites and the nature of the information that they expose.
With no prerequisites to indicate that they should be enabled, the env
, java
, and os
contributors are disabled by default.
Each can be enabled by setting its management.info.<id>.enabled
property to true
.
The build
and git
info contributors are enabled by default.
Each can be disabled by setting its management.info.<id>.enabled
property to false
.
Alternatively, to disable every contributor that is usually enabled by default, set the management.info.defaults.enabled
property to false
.
Custom Application Information
When the env
contributor is enabled, 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.
For example, you could add the following settings to your application.properties
file:
-
Properties
-
YAML
info.app.encoding=UTF-8
info.app.java.source=17
info.app.java.target=17
info:
app:
encoding: "UTF-8"
java:
source: "17"
target: "17"
Rather than hardcoding those values, you could also expand info properties at build time. Assuming you use Maven, you could rewrite the preceding example as follows:
|
Git Commit Information
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, you can use the info
endpoint to expose these properties.
A GitProperties bean is auto-configured if a git.properties file is available at the root of the classpath.
See "how to generate git information" for more detail.
|
By default, the endpoint exposes git.branch
, git.commit.id
, and git.commit.time
properties, if present.
If you do not want any of these properties in the endpoint response, they need to be excluded from the git.properties
file.
If you want to display the full git information (that is, the full content of git.properties
), use the management.info.git.mode
property, as follows:
-
Properties
-
YAML
management.info.git.mode=full
management:
info:
git:
mode: "full"
To disable the git commit information from the info
endpoint completely, set the management.info.git.enabled
property to false
, as follows:
-
Properties
-
YAML
management.info.git.enabled=false
management:
info:
git:
enabled: false
Build Information
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.
The Maven and Gradle plugins can both generate that file. See "how to generate build information" for more details. |
Java Information
The info
endpoint publishes information about your Java runtime environment, see JavaInfo
for more details.
OS Information
The info
endpoint publishes information about your Operating System, see OsInfo
for more details.
Writing Custom InfoContributors
To provide custom application information, you can register Spring beans that implement the InfoContributor
interface.
The following example contributes an example
entry with a single value:
-
Java
-
Kotlin
import java.util.Collections;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;
@Component
public class MyInfoContributor implements InfoContributor {
@Override
public void contribute(Info.Builder builder) {
builder.withDetail("example", Collections.singletonMap("key", "value"));
}
}
import org.springframework.boot.actuate.info.Info
import org.springframework.boot.actuate.info.InfoContributor
import org.springframework.stereotype.Component
import java.util.Collections
@Component
class MyInfoContributor : InfoContributor {
override fun contribute(builder: Info.Builder) {
builder.withDetail("example", Collections.singletonMap("key", "value"))
}
}
If you reach the info
endpoint, you should see a response that contains the following additional entry:
{
"example": {
"key" : "value"
}
}