Adjust auto-configuration to register at most one Vault health indicator.
Fixes gh-676 Original pull request: gh-677
This commit is contained in:
committed by
Mark Paluch
parent
f88df294c3
commit
e92c7f5118
@@ -30,7 +30,7 @@ import org.springframework.context.annotation.Import;
|
||||
* {@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)
|
||||
@@ -39,7 +39,7 @@ import org.springframework.context.annotation.Import;
|
||||
@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 {
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.vault.core.ReactiveVaultOperations;
|
||||
/**
|
||||
* Configuration for {@link VaultReactiveHealthIndicator}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Mark Paluch, Rastislav Zlacky
|
||||
* @since 2.0
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.mockito.Mockito.mock;
|
||||
/**
|
||||
* Unit tests for {@link VaultHealthIndicatorAutoConfiguration}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Mark Paluch, Rastislav Zlacky
|
||||
*/
|
||||
class VaultHealthIndicatorAutoConfigurationTests {
|
||||
|
||||
@@ -62,6 +62,17 @@ class VaultHealthIndicatorAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@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
|
||||
@@ -74,7 +85,7 @@ class VaultHealthIndicatorAutoConfigurationTests {
|
||||
static class ReactiveConfiguration {
|
||||
|
||||
@Bean
|
||||
ReactiveVaultOperations vaultOperations() {
|
||||
ReactiveVaultOperations reactiveVaultOperations() {
|
||||
return mock(ReactiveVaultOperations.class);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user