Skip to content

Commit 56b8494

Browse files
committed
Disable the env info contributor by default
Closes gh-28311
1 parent f98c1e7 commit 56b8494

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class InfoContributorAutoConfiguration {
5555
public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 10;
5656

5757
@Bean
58-
@ConditionalOnEnabledInfoContributor("env")
58+
@ConditionalOnEnabledInfoContributor(value = "env", fallback = InfoContributorFallback.DISABLE)
5959
@Order(DEFAULT_ORDER)
6060
public EnvironmentInfoContributor envInfoContributor(ConfigurableEnvironment environment) {
6161
return new EnvironmentInfoContributor(environment);

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/info/InfoContributorAutoConfigurationTests.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,28 @@ class InfoContributorAutoConfigurationTests {
4949
.withConfiguration(AutoConfigurations.of(InfoContributorAutoConfiguration.class));
5050

5151
@Test
52-
void disableEnvContributor() {
53-
this.contextRunner.withPropertyValues("management.info.env.enabled=false")
54-
.run((context) -> assertThat(context).doesNotHaveBean(EnvironmentInfoContributor.class));
52+
void envContributor() {
53+
this.contextRunner.withPropertyValues("management.info.env.enabled=true")
54+
.run((context) -> assertThat(context).hasSingleBean(EnvironmentInfoContributor.class));
5555
}
5656

5757
@Test
5858
void defaultInfoContributorsEnabled() {
59-
this.contextRunner.run((context) -> {
60-
assertThat(context).hasSingleBean(EnvironmentInfoContributor.class);
61-
assertThat(context.getBeansOfType(InfoContributor.class)).hasSize(1);
62-
});
59+
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(InfoContributor.class));
6360
}
6461

6562
@Test
66-
void defaultInfoContributorsDisabled() {
67-
this.contextRunner.withPropertyValues("management.info.defaults.enabled=false")
63+
void defaultInfoContributorsEnabledWithPrerequisitesInPlace() {
64+
this.contextRunner.withUserConfiguration(GitPropertiesConfiguration.class, BuildPropertiesConfiguration.class)
65+
.run((context) -> assertThat(context.getBeansOfType(InfoContributor.class)).hasSize(2)
66+
.satisfies((contributors) -> assertThat(contributors.values())
67+
.hasOnlyElementsOfTypes(BuildInfoContributor.class, GitInfoContributor.class)));
68+
}
69+
70+
@Test
71+
void defaultInfoContributorsDisabledWithPrerequisitesInPlace() {
72+
this.contextRunner.withUserConfiguration(GitPropertiesConfiguration.class, BuildPropertiesConfiguration.class)
73+
.withPropertyValues("management.info.defaults.enabled=false")
6874
.run((context) -> assertThat(context).doesNotHaveBean(InfoContributor.class));
6975
}
7076

spring-boot-project/spring-boot-docs/src/docs/asciidoc/actuator/endpoints.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,18 +1174,18 @@ When appropriate, Spring auto-configures the following `InfoContributor` beans:
11741174
Whether or not an individual contributor is enabled is controlled by its `management.info.<id>.enabled` property.
11751175
Different contributors have different defaults for this property, depending on their prerequisites and the nature of the information that they expose.
11761176

1177-
With no prequisites to indicate that it should be enabled, the `java` contributor is disabled by default.
1178-
You can enable it by setting the configprop:management.info.java.enabled[] property to `true`.
1177+
With no prequisites to indicate that they should be enabled, the `env` and `java` contributors are disabled by default.
1178+
You can enable them by setting the configprop:management.info.env.enabled[] or configprop:management.info.java.enabled[] properties to `true`.
11791179

1180-
The `env`, `git`, and `build` info contributors are enabled by default.
1180+
The `build` and `git` info contributors are enabled by default.
11811181
Each can be disabled by setting its `management.info.<id>.enabled` property to `false`.
11821182
Alternatively, to disable every contributor that is usually enabled by default, set the configprop:management.info.defaults.enabled[] property to `false`.
11831183

11841184

11851185

11861186
[[actuator.endpoints.info.custom-application-information]]
11871187
==== Custom Application Information
1188-
You can customize the data exposed by the `info` endpoint by setting `+info.*+` Spring properties.
1188+
When the `env` contributor is enabled, you can customize the data exposed by the `info` endpoint by setting `+info.*+` Spring properties.
11891189
All `Environment` properties under the `info` key are automatically exposed.
11901190
For example, you could add the following settings to your `application.properties` file:
11911191

0 commit comments

Comments
 (0)