Skip to content

Commit d7652e8

Browse files
committed
Make sure Reactive health indicators take precedence
This commit restores the highest precedence of reactive HealthContributor over imperative one. Previously, both would be registered, leading to duplicate entries in health output. Closes gh-18748
1 parent a664ead commit d7652e8

12 files changed

+57
-24
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
@ConditionalOnClass({ Cluster.class, CassandraOperations.class })
4848
@ConditionalOnBean(CassandraOperations.class)
4949
@ConditionalOnEnabledHealthIndicator("cassandra")
50-
@AutoConfigureAfter({ CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class })
50+
@AutoConfigureAfter({ CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
51+
CassandraReactiveHealthContributorAutoConfiguration.class })
5152
public class CassandraHealthContributorAutoConfiguration
5253
extends CompositeHealthContributorConfiguration<CassandraHealthIndicator, CassandraOperations> {
5354

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public class CassandraReactiveHealthContributorAutoConfiguration extends
5151
CompositeReactiveHealthContributorConfiguration<CassandraReactiveHealthIndicator, ReactiveCassandraOperations> {
5252

5353
@Bean
54-
@ConditionalOnMissingBean(name = { "cassandraReactiveHealthIndicator", "cassandraReactiveHealthContributor" })
55-
public ReactiveHealthContributor cassandraReactiveHealthContributor(
54+
@ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
55+
public ReactiveHealthContributor cassandraHealthContributor(
5656
Map<String, ReactiveCassandraOperations> reactiveCassandraOperations) {
5757
return createContributor(reactiveCassandraOperations);
5858
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthContributorAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
@ConditionalOnClass(Cluster.class)
4646
@ConditionalOnBean(Cluster.class)
4747
@ConditionalOnEnabledHealthIndicator("couchbase")
48-
@AutoConfigureAfter({ CouchbaseAutoConfiguration.class })
48+
@AutoConfigureAfter({ CouchbaseAutoConfiguration.class, CouchbaseReactiveHealthContributorAutoConfiguration.class })
4949
public class CouchbaseHealthContributorAutoConfiguration
5050
extends CompositeHealthContributorConfiguration<CouchbaseHealthIndicator, Cluster> {
5151

5252
@Bean
53-
@ConditionalOnMissingBean(name = { "couchbaseHealthContributor", "couchbaseHealthContributor" })
53+
@ConditionalOnMissingBean(name = { "couchbaseHealthIndicator", "couchbaseHealthContributor" })
5454
public HealthContributor couchbaseHealthContributor(Map<String, Cluster> clusters) {
5555
return createContributor(clusters);
5656
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthContributorAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public class CouchbaseReactiveHealthContributorAutoConfiguration
5050
extends CompositeReactiveHealthContributorConfiguration<CouchbaseReactiveHealthIndicator, Cluster> {
5151

5252
@Bean
53-
@ConditionalOnMissingBean(name = { "couchbaseReactiveHealthIndicator", "couchbaseReactiveHealthContributor" })
54-
public ReactiveHealthContributor couchbaseReactiveHealthContributor(Map<String, Cluster> clusters) {
53+
@ConditionalOnMissingBean(name = { "couchbaseHealthIndicator", "couchbaseHealthContributor" })
54+
public ReactiveHealthContributor couchbaseHealthContributor(Map<String, Cluster> clusters) {
5555
return createContributor(clusters);
5656
}
5757

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mongo/MongoHealthContributorAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
@ConditionalOnClass(MongoTemplate.class)
4444
@ConditionalOnBean(MongoTemplate.class)
4545
@ConditionalOnEnabledHealthIndicator("mongo")
46-
@AutoConfigureAfter({ MongoAutoConfiguration.class, MongoDataAutoConfiguration.class })
46+
@AutoConfigureAfter({ MongoAutoConfiguration.class, MongoDataAutoConfiguration.class,
47+
MongoReactiveHealthContributorAutoConfiguration.class })
4748
public class MongoHealthContributorAutoConfiguration
4849
extends CompositeHealthContributorConfiguration<MongoHealthIndicator, MongoTemplate> {
4950

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mongo/MongoReactiveHealthContributorAutoConfiguration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ public class MongoReactiveHealthContributorAutoConfiguration
5050
extends CompositeReactiveHealthContributorConfiguration<MongoReactiveHealthIndicator, ReactiveMongoTemplate> {
5151

5252
@Bean
53-
@ConditionalOnMissingBean(name = { "mongoReactiveHealthIndicator", "mongoReactiveHealthContributor" })
54-
public ReactiveHealthContributor mongoReactiveHealthContributor(
55-
Map<String, ReactiveMongoTemplate> reactiveMongoTemplates) {
53+
@ConditionalOnMissingBean(name = { "mongoHealthIndicator", "mongoHealthContributor" })
54+
public ReactiveHealthContributor mongoHealthContributor(Map<String, ReactiveMongoTemplate> reactiveMongoTemplates) {
5655
return createContributor(reactiveMongoTemplates);
5756
}
5857

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/redis/RedisHealthContributorAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
@ConditionalOnClass(RedisConnectionFactory.class)
4646
@ConditionalOnBean(RedisConnectionFactory.class)
4747
@ConditionalOnEnabledHealthIndicator("redis")
48-
@AutoConfigureAfter(RedisAutoConfiguration.class)
48+
@AutoConfigureAfter({ RedisAutoConfiguration.class, RedisReactiveHealthContributorAutoConfiguration.class })
4949
public class RedisHealthContributorAutoConfiguration
5050
extends CompositeHealthContributorConfiguration<RedisHealthIndicator, RedisConnectionFactory> {
5151

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/redis/RedisReactiveHealthContributorAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public class RedisReactiveHealthContributorAutoConfiguration extends
6060
}
6161

6262
@Bean
63-
@ConditionalOnMissingBean(name = { "redisReactiveHealthIndicator", "redisReactiveHealthContributor" })
64-
public ReactiveHealthContributor redisReactiveHealthContributor() {
63+
@ConditionalOnMissingBean(name = { "redisHealthIndicator", "redisHealthContributor" })
64+
public ReactiveHealthContributor redisHealthContributor() {
6565
return createContributor(this.redisConnectionFactories);
6666
}
6767

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfigurationTests.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.junit.jupiter.api.Test;
2020

21+
import org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorAutoConfigurationTests.CassandraConfiguration;
2122
import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration;
2223
import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator;
2324
import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator;
@@ -44,13 +45,23 @@ class CassandraReactiveHealthContributorAutoConfigurationTests {
4445
@Test
4546
void runShouldCreateIndicator() {
4647
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CassandraReactiveHealthIndicator.class)
47-
.doesNotHaveBean(CassandraHealthIndicator.class));
48+
.hasBean("cassandraHealthContributor"));
49+
}
50+
51+
@Test
52+
void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() {
53+
this.contextRunner
54+
.withConfiguration(AutoConfigurations.of(CassandraConfiguration.class,
55+
CassandraHealthContributorAutoConfiguration.class))
56+
.run((context) -> assertThat(context).hasSingleBean(CassandraReactiveHealthIndicator.class)
57+
.hasBean("cassandraHealthContributor").doesNotHaveBean(CassandraHealthIndicator.class));
4858
}
4959

5060
@Test
5161
void runWhenDisabledShouldNotCreateIndicator() {
5262
this.contextRunner.withPropertyValues("management.health.cassandra.enabled:false")
53-
.run((context) -> assertThat(context).doesNotHaveBean(CassandraReactiveHealthIndicator.class));
63+
.run((context) -> assertThat(context).doesNotHaveBean(CassandraReactiveHealthIndicator.class)
64+
.doesNotHaveBean("cassandraHealthContributor"));
5465
}
5566

5667
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthContributorAutoConfigurationTests.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,21 @@ class CouchbaseReactiveHealthContributorAutoConfigurationTests {
4343
@Test
4444
void runShouldCreateIndicator() {
4545
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(CouchbaseReactiveHealthIndicator.class)
46-
.doesNotHaveBean(CouchbaseHealthIndicator.class));
46+
.hasBean("couchbaseHealthContributor"));
47+
}
48+
49+
@Test
50+
void runWithRegularIndicatorShouldOnlyCreateReactiveIndicator() {
51+
this.contextRunner.withConfiguration(AutoConfigurations.of(CouchbaseHealthContributorAutoConfiguration.class))
52+
.run((context) -> assertThat(context).hasSingleBean(CouchbaseReactiveHealthIndicator.class)
53+
.hasBean("couchbaseHealthContributor").doesNotHaveBean(CouchbaseHealthIndicator.class));
4754
}
4855

4956
@Test
5057
void runWhenDisabledShouldNotCreateIndicator() {
5158
this.contextRunner.withPropertyValues("management.health.couchbase.enabled:false")
52-
.run((context) -> assertThat(context).doesNotHaveBean(CouchbaseReactiveHealthIndicator.class));
59+
.run((context) -> assertThat(context).doesNotHaveBean(CouchbaseReactiveHealthIndicator.class)
60+
.doesNotHaveBean("couchbaseHealthContributor"));
5361
}
5462

5563
}

0 commit comments

Comments
 (0)