Skip to content

Commit

Permalink
Adjust auto-configuration to register at most one Vault health indica…
Browse files Browse the repository at this point in the history
…tor.

Fixes gh-676
Original pull request: gh-677
  • Loading branch information
raestio authored and mp911de committed Mar 28, 2023
1 parent 360b1c1 commit fe4db76
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
* Auto-configuration} for Vault providing beans for the application context.
*
* @author Mark Paluch
* @author Mark Paluch, Rastislav Zlacky
* @since 2.0
*/
@Configuration(proxyBeanMethods = false)
Expand All @@ -39,7 +39,7 @@
@ConditionalOnProperty(name = "spring.cloud.vault.enabled", matchIfMissing = true)
@AutoConfigureBefore(HealthContributorAutoConfiguration.class)
@AutoConfigureAfter({ VaultAutoConfiguration.class, VaultReactiveAutoConfiguration.class })
@Import({ VaultHealthIndicatorConfiguration.class, VaultReactiveHealthIndicatorConfiguration.class })
@Import({ VaultReactiveHealthIndicatorConfiguration.class, VaultHealthIndicatorConfiguration.class })
public class VaultHealthIndicatorAutoConfiguration {

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Configuration for {@link VaultReactiveHealthIndicator}.
*
* @author Mark Paluch
* @author Mark Paluch, Rastislav Zlacky
* @since 2.0
*/
@Configuration(proxyBeanMethods = false)
Expand All @@ -47,9 +47,9 @@ class VaultReactiveHealthIndicatorConfiguration
this.reactiveVaultTemplates = reactiveVaultTemplates;
}

@Bean
@ConditionalOnMissingBean(name = { "vaultReactiveHealthIndicator" })
ReactiveHealthContributor vaultReactiveHealthIndicator() {
@Bean(name = { "vaultHealthIndicator", "vaultReactiveHealthIndicator" })
@ConditionalOnMissingBean(name = { "vaultHealthIndicator" })
ReactiveHealthContributor vaultHealthIndicator() {
return createContributor(this.reactiveVaultTemplates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* Unit tests for {@link VaultHealthIndicatorAutoConfiguration}.
*
* @author Mark Paluch
* @author Mark Paluch, Rastislav Zlacky
*/
class VaultHealthIndicatorAutoConfigurationTests {

Expand Down Expand Up @@ -62,6 +62,17 @@ void shouldConfigureReactiveHealthIndicator() {

}

@Test
void shouldConfigureSingleHealthIndicator() {

this.contextRunner.withUserConfiguration(ImperativeConfiguration.class, ReactiveConfiguration.class)
.run(context -> {
assertThat(context).hasBean("vaultHealthIndicator")
.hasSingleBean(VaultReactiveHealthIndicator.class)
.doesNotHaveBean(VaultHealthIndicator.class);
});
}

static class ImperativeConfiguration {

@Bean
Expand All @@ -74,7 +85,7 @@ VaultOperations vaultOperations() {
static class ReactiveConfiguration {

@Bean
ReactiveVaultOperations vaultOperations() {
ReactiveVaultOperations reactiveVaultOperations() {
return mock(ReactiveVaultOperations.class);
}

Expand Down

0 comments on commit fe4db76

Please sign in to comment.