Skip to content

Commit f8141cb

Browse files
committed
Restore use of management.health.*.enabled keys
The move of health.* keys to management.health.* broke them as they are not defined as configuration keys and `ManagementServerProperties` is strict on the whole management namespace. This commit updates the tests to actually include that properties class and relax the "ignoreUnknownFields" condition so that extra attributes can be defined on the "management" namespace. Fixes spring-projectsgh-2115
1 parent 43fb5b6 commit f8141cb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @author Dave Syer
3434
* @see ServerProperties
3535
*/
36-
@ConfigurationProperties(prefix = "management", ignoreUnknownFields = false)
36+
@ConfigurationProperties(prefix = "management", ignoreUnknownFields = true)
3737
public class ManagementServerProperties implements SecurityPrequisite {
3838

3939
private static final String SECURITY_CHECK_CLASS = "org.springframework.security.config.http.SessionCreationPolicy";

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public void close() {
7676
@Test
7777
public void defaultHealthIndicator() {
7878
this.context = new AnnotationConfigApplicationContext();
79-
this.context.register(HealthIndicatorAutoConfiguration.class);
79+
this.context.register(HealthIndicatorAutoConfiguration.class,
80+
ManagementServerProperties.class);
8081
EnvironmentTestUtils.addEnvironment(this.context,
8182
"management.health.diskspace.enabled:false");
8283
this.context.refresh();
@@ -91,6 +92,7 @@ public void defaultHealthIndicator() {
9192
public void redisHealthIndicator() {
9293
this.context = new AnnotationConfigApplicationContext();
9394
this.context.register(RedisAutoConfiguration.class,
95+
ManagementServerProperties.class,
9496
HealthIndicatorAutoConfiguration.class);
9597
EnvironmentTestUtils.addEnvironment(this.context,
9698
"management.health.diskspace.enabled:false");
@@ -106,6 +108,7 @@ public void redisHealthIndicator() {
106108
public void notRedisHealthIndicator() {
107109
this.context = new AnnotationConfigApplicationContext();
108110
this.context.register(RedisAutoConfiguration.class,
111+
ManagementServerProperties.class,
109112
HealthIndicatorAutoConfiguration.class);
110113
EnvironmentTestUtils.addEnvironment(this.context,
111114
"management.health.redis.enabled:false",
@@ -122,6 +125,7 @@ public void notRedisHealthIndicator() {
122125
public void mongoHealthIndicator() {
123126
this.context = new AnnotationConfigApplicationContext();
124127
this.context.register(MongoAutoConfiguration.class,
128+
ManagementServerProperties.class,
125129
MongoDataAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
126130
EnvironmentTestUtils.addEnvironment(this.context,
127131
"management.health.diskspace.enabled:false");
@@ -137,6 +141,7 @@ public void mongoHealthIndicator() {
137141
public void notMongoHealthIndicator() {
138142
this.context = new AnnotationConfigApplicationContext();
139143
this.context.register(MongoAutoConfiguration.class,
144+
ManagementServerProperties.class,
140145
MongoDataAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
141146
EnvironmentTestUtils.addEnvironment(this.context,
142147
"management.health.mongo.enabled:false",
@@ -165,6 +170,7 @@ public void combinedHealthIndicator() {
165170
public void dataSourceHealthIndicator() {
166171
this.context = new AnnotationConfigApplicationContext();
167172
this.context.register(EmbeddedDataSourceConfiguration.class,
173+
ManagementServerProperties.class,
168174
HealthIndicatorAutoConfiguration.class);
169175
EnvironmentTestUtils.addEnvironment(this.context,
170176
"management.health.diskspace.enabled:false");
@@ -180,6 +186,7 @@ public void dataSourceHealthIndicator() {
180186
public void dataSourceHealthIndicatorWithCustomValidationQuery() {
181187
this.context = new AnnotationConfigApplicationContext();
182188
this.context.register(PropertyPlaceholderAutoConfiguration.class,
189+
ManagementServerProperties.class,
183190
DataSourceProperties.class, DataSourceConfig.class,
184191
DataSourcePoolMetadataProvidersConfiguration.class,
185192
HealthIndicatorAutoConfiguration.class);
@@ -200,6 +207,7 @@ public void dataSourceHealthIndicatorWithCustomValidationQuery() {
200207
public void notDataSourceHealthIndicator() {
201208
this.context = new AnnotationConfigApplicationContext();
202209
this.context.register(EmbeddedDataSourceConfiguration.class,
210+
ManagementServerProperties.class,
203211
HealthIndicatorAutoConfiguration.class);
204212
EnvironmentTestUtils.addEnvironment(this.context,
205213
"management.health.db.enabled:false",
@@ -216,6 +224,7 @@ public void notDataSourceHealthIndicator() {
216224
public void rabbitHealthIndicator() {
217225
this.context = new AnnotationConfigApplicationContext();
218226
this.context.register(RabbitAutoConfiguration.class,
227+
ManagementServerProperties.class,
219228
HealthIndicatorAutoConfiguration.class);
220229
EnvironmentTestUtils.addEnvironment(this.context,
221230
"management.health.diskspace.enabled:false");
@@ -231,6 +240,7 @@ public void rabbitHealthIndicator() {
231240
public void notRabbitHealthIndicator() {
232241
this.context = new AnnotationConfigApplicationContext();
233242
this.context.register(RabbitAutoConfiguration.class,
243+
ManagementServerProperties.class,
234244
HealthIndicatorAutoConfiguration.class);
235245
EnvironmentTestUtils.addEnvironment(this.context,
236246
"management.health.rabbit.enabled:false",
@@ -247,6 +257,7 @@ public void notRabbitHealthIndicator() {
247257
public void solrHeathIndicator() {
248258
this.context = new AnnotationConfigApplicationContext();
249259
this.context.register(SolrAutoConfiguration.class,
260+
ManagementServerProperties.class,
250261
HealthIndicatorAutoConfiguration.class);
251262
EnvironmentTestUtils.addEnvironment(this.context,
252263
"management.health.diskspace.enabled:false");
@@ -262,6 +273,7 @@ public void solrHeathIndicator() {
262273
public void notSolrHeathIndicator() {
263274
this.context = new AnnotationConfigApplicationContext();
264275
this.context.register(SolrAutoConfiguration.class,
276+
ManagementServerProperties.class,
265277
HealthIndicatorAutoConfiguration.class);
266278
EnvironmentTestUtils.addEnvironment(this.context,
267279
"management.health.solr.enabled:false",

0 commit comments

Comments
 (0)