From 19f393c9d01a875f2aac399e9ce6fe28b7e36ea5 Mon Sep 17 00:00:00 2001 From: spencergibb Date: Fri, 21 May 2021 17:06:22 -0400 Subject: [PATCH] Only register beans if config discovery is enabled. --- .../configclient/ConsulConfigServerBootstrapper.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulConfigServerBootstrapper.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulConfigServerBootstrapper.java index 61db5745..fae7b12e 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulConfigServerBootstrapper.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/configclient/ConsulConfigServerBootstrapper.java @@ -45,10 +45,16 @@ public class ConsulConfigServerBootstrapper implements Bootstrapper { // create consul client registry.registerIfAbsent(ConsulProperties.class, context -> { Binder binder = context.get(Binder.class); + if (!isDiscoveryEnabled(binder)) { + return null; + } return binder.bind(ConsulProperties.PREFIX, Bindable.of(ConsulProperties.class), getBindHandler(context)) .orElseGet(ConsulProperties::new); }); registry.registerIfAbsent(ConsulClient.class, context -> { + if (!isDiscoveryEnabled(context.get(Binder.class))) { + return null; + } ConsulProperties consulProperties = context.get(ConsulProperties.class); return ConsulAutoConfiguration.createConsulClient(consulProperties); }); @@ -66,6 +72,9 @@ public class ConsulConfigServerBootstrapper implements Bootstrapper { }); // promote discovery client if created registry.addCloseListener(event -> { + if (!isDiscoveryEnabled(event.getBootstrapContext().get(Binder.class))) { + return; + } ConsulDiscoveryClient discoveryClient = event.getBootstrapContext().get(ConsulDiscoveryClient.class); if (discoveryClient != null) { event.getApplicationContext().getBeanFactory().registerSingleton("consulDiscoveryClient",