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
This commit is contained in:
parent
a94ab673a3
commit
8f9fd97095
|
|
@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Configuration to adapt legacy deprecated health endpoint classes and interfaces.
|
||||
|
|
@ -46,7 +47,7 @@ class LegacyHealthEndpointCompatibilityConfiguration {
|
|||
@ConditionalOnMissingBean
|
||||
HealthAggregator healthAggregator(HealthIndicatorProperties healthIndicatorProperties) {
|
||||
OrderedHealthAggregator aggregator = new OrderedHealthAggregator();
|
||||
if (healthIndicatorProperties.getOrder() != null) {
|
||||
if (!CollectionUtils.isEmpty(healthIndicatorProperties.getOrder())) {
|
||||
aggregator.setStatusOrder(healthIndicatorProperties.getOrder());
|
||||
}
|
||||
return aggregator;
|
||||
|
|
@ -56,7 +57,7 @@ class LegacyHealthEndpointCompatibilityConfiguration {
|
|||
@ConditionalOnMissingBean
|
||||
HealthStatusHttpMapper healthStatusHttpMapper(HealthIndicatorProperties healthIndicatorProperties) {
|
||||
HealthStatusHttpMapper mapper = new HealthStatusHttpMapper();
|
||||
if (healthIndicatorProperties.getHttpMapping() != null) {
|
||||
if (!CollectionUtils.isEmpty(healthIndicatorProperties.getHttpMapping())) {
|
||||
mapper.setStatusMapping(healthIndicatorProperties.getHttpMapping());
|
||||
}
|
||||
return mapper;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@
|
|||
package org.springframework.boot.actuate.autoconfigure.health;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
|
@ -271,6 +273,26 @@ class HealthEndpointAutoConfigurationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test // gh-18354
|
||||
void runCreatesLegacyHealthAggregator() {
|
||||
this.contextRunner.run((context) -> {
|
||||
HealthAggregator aggregator = context.getBean(HealthAggregator.class);
|
||||
Map<String, Health> healths = new LinkedHashMap<>();
|
||||
healths.put("one", Health.up().build());
|
||||
healths.put("two", Health.down().build());
|
||||
Health result = aggregator.aggregate(healths);
|
||||
assertThat(result.getStatus()).isEqualTo(Status.DOWN);
|
||||
});
|
||||
}
|
||||
|
||||
@Test // gh-18354
|
||||
void runCreatesLegacyHealthStatusHttpMapper() {
|
||||
this.contextRunner.run((context) -> {
|
||||
HealthStatusHttpMapper mapper = context.getBean(HealthStatusHttpMapper.class);
|
||||
assertThat(mapper.mapStatus(Status.DOWN)).isEqualTo(503);
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class HealthIndicatorsConfiguration {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue