Skip to content

Commit 8f9fd97

Browse files
committed
Don't reset defaults if source collection is empty
Update `LegacyHealthEndpointCompatibilityConfiguration` to ensure that the default configuration is only overwritten when the user has explicitly set new values. Fixes gh-18354
1 parent a94ab67 commit 8f9fd97

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointCompatibilityConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3131
import org.springframework.context.annotation.Bean;
3232
import org.springframework.context.annotation.Configuration;
33+
import org.springframework.util.CollectionUtils;
3334

3435
/**
3536
* Configuration to adapt legacy deprecated health endpoint classes and interfaces.
@@ -46,7 +47,7 @@ class LegacyHealthEndpointCompatibilityConfiguration {
4647
@ConditionalOnMissingBean
4748
HealthAggregator healthAggregator(HealthIndicatorProperties healthIndicatorProperties) {
4849
OrderedHealthAggregator aggregator = new OrderedHealthAggregator();
49-
if (healthIndicatorProperties.getOrder() != null) {
50+
if (!CollectionUtils.isEmpty(healthIndicatorProperties.getOrder())) {
5051
aggregator.setStatusOrder(healthIndicatorProperties.getOrder());
5152
}
5253
return aggregator;
@@ -56,7 +57,7 @@ HealthAggregator healthAggregator(HealthIndicatorProperties healthIndicatorPrope
5657
@ConditionalOnMissingBean
5758
HealthStatusHttpMapper healthStatusHttpMapper(HealthIndicatorProperties healthIndicatorProperties) {
5859
HealthStatusHttpMapper mapper = new HealthStatusHttpMapper();
59-
if (healthIndicatorProperties.getHttpMapping() != null) {
60+
if (!CollectionUtils.isEmpty(healthIndicatorProperties.getHttpMapping())) {
6061
mapper.setStatusMapping(healthIndicatorProperties.getHttpMapping());
6162
}
6263
return mapper;

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfigurationTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package org.springframework.boot.actuate.autoconfigure.health;
1818

1919
import java.util.Collections;
20+
import java.util.LinkedHashMap;
2021
import java.util.List;
22+
import java.util.Map;
2123

2224
import org.junit.jupiter.api.Test;
2325
import reactor.core.publisher.Mono;
@@ -271,6 +273,26 @@ void runWhenHasReactiveHealthEndpointWebExtensionBeanDoesNotCreateExtraReactiveH
271273
});
272274
}
273275

276+
@Test // gh-18354
277+
void runCreatesLegacyHealthAggregator() {
278+
this.contextRunner.run((context) -> {
279+
HealthAggregator aggregator = context.getBean(HealthAggregator.class);
280+
Map<String, Health> healths = new LinkedHashMap<>();
281+
healths.put("one", Health.up().build());
282+
healths.put("two", Health.down().build());
283+
Health result = aggregator.aggregate(healths);
284+
assertThat(result.getStatus()).isEqualTo(Status.DOWN);
285+
});
286+
}
287+
288+
@Test // gh-18354
289+
void runCreatesLegacyHealthStatusHttpMapper() {
290+
this.contextRunner.run((context) -> {
291+
HealthStatusHttpMapper mapper = context.getBean(HealthStatusHttpMapper.class);
292+
assertThat(mapper.mapStatus(Status.DOWN)).isEqualTo(503);
293+
});
294+
}
295+
274296
@Configuration(proxyBeanMethods = false)
275297
static class HealthIndicatorsConfiguration {
276298

0 commit comments

Comments
 (0)