diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfiguration.java index 1b3ff48d43e..c996e02cf5a 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfiguration.java @@ -55,7 +55,7 @@ public class InfoContributorAutoConfiguration { public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 10; @Bean - @ConditionalOnEnabledInfoContributor("env") + @ConditionalOnEnabledInfoContributor(value = "env", fallback = InfoContributorFallback.DISABLE) @Order(DEFAULT_ORDER) public EnvironmentInfoContributor envInfoContributor(ConfigurableEnvironment environment) { return new EnvironmentInfoContributor(environment); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfigurationTests.java index 6c9eaf92abb..16aab168f98 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfigurationTests.java @@ -49,22 +49,28 @@ class InfoContributorAutoConfigurationTests { .withConfiguration(AutoConfigurations.of(InfoContributorAutoConfiguration.class)); @Test - void disableEnvContributor() { - this.contextRunner.withPropertyValues("management.info.env.enabled=false") - .run((context) -> assertThat(context).doesNotHaveBean(EnvironmentInfoContributor.class)); + void envContributor() { + this.contextRunner.withPropertyValues("management.info.env.enabled=true") + .run((context) -> assertThat(context).hasSingleBean(EnvironmentInfoContributor.class)); } @Test void defaultInfoContributorsEnabled() { - this.contextRunner.run((context) -> { - assertThat(context).hasSingleBean(EnvironmentInfoContributor.class); - assertThat(context.getBeansOfType(InfoContributor.class)).hasSize(1); - }); + this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(InfoContributor.class)); } @Test - void defaultInfoContributorsDisabled() { - this.contextRunner.withPropertyValues("management.info.defaults.enabled=false") + void defaultInfoContributorsEnabledWithPrerequisitesInPlace() { + this.contextRunner.withUserConfiguration(GitPropertiesConfiguration.class, BuildPropertiesConfiguration.class) + .run((context) -> assertThat(context.getBeansOfType(InfoContributor.class)).hasSize(2) + .satisfies((contributors) -> assertThat(contributors.values()) + .hasOnlyElementsOfTypes(BuildInfoContributor.class, GitInfoContributor.class))); + } + + @Test + void defaultInfoContributorsDisabledWithPrerequisitesInPlace() { + this.contextRunner.withUserConfiguration(GitPropertiesConfiguration.class, BuildPropertiesConfiguration.class) + .withPropertyValues("management.info.defaults.enabled=false") .run((context) -> assertThat(context).doesNotHaveBean(InfoContributor.class)); } diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/endpoints.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/endpoints.adoc index f0408129cf9..8547c06fb05 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/endpoints.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/endpoints.adoc @@ -1174,10 +1174,10 @@ When appropriate, Spring auto-configures the following `InfoContributor` beans: Whether or not an individual contributor is enabled is controlled by its `management.info..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 prequisites to indicate that it should be enabled, the `java` contributor is disabled by default. -You can enable it by setting the configprop:management.info.java.enabled[] property to `true`. +With no prequisites to indicate that they should be enabled, the `env` and `java` contributors are disabled by default. +You can enable them by setting the configprop:management.info.env.enabled[] or configprop:management.info.java.enabled[] properties to `true`. -The `env`, `git`, and `build` info contributors are enabled by default. +The `build` and `git` info contributors are enabled by default. Each can be disabled by setting its `management.info..enabled` property to `false`. Alternatively, to disable every contributor that is usually enabled by default, set the configprop:management.info.defaults.enabled[] property to `false`. @@ -1185,7 +1185,7 @@ Alternatively, to disable every contributor that is usually enabled by default, [[actuator.endpoints.info.custom-application-information]] ==== Custom Application Information -You can customize the data exposed by the `info` endpoint by setting `+info.*+` Spring properties. +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: