From 463aaa78818f6043aa6e1ac23ae68e9ec98f1b7c Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Tue, 12 Mar 2024 10:23:41 -0400 Subject: [PATCH] Register ZookeeperProperties in Bootstraper (#331) Co-authored-by: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> --- .../ZookeeperConfigServerBootstrapper.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperConfigServerBootstrapper.java b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperConfigServerBootstrapper.java index 2093a2ba..26171eb1 100644 --- a/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperConfigServerBootstrapper.java +++ b/spring-cloud-zookeeper-discovery/src/main/java/org/springframework/cloud/zookeeper/discovery/configclient/ZookeeperConfigServerBootstrapper.java @@ -35,6 +35,7 @@ import org.springframework.cloud.config.client.ConfigServerConfigDataLocationResolver.PropertyResolver; import org.springframework.cloud.config.client.ConfigServerInstanceProvider; import org.springframework.cloud.zookeeper.CuratorFactory; +import org.springframework.cloud.zookeeper.ZookeeperProperties; import org.springframework.cloud.zookeeper.discovery.ConditionalOnZookeeperDiscoveryEnabled; import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryClient; import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryProperties; @@ -67,6 +68,17 @@ public void initialize(BootstrapRegistry registry) { return; } + //Register ZookeeperProperties instead of in CuratorFactor.registerCurator here so we can properly resolve the properties. + //We need to use the PropertyResolver to do so but that is not available in CuratorFactory since it is a class + //from Spring Cloud Config. + registry.registerIfAbsent(ZookeeperProperties.class, context -> { + if (!isEnabled(context)) { + return null; + } + PropertyResolver propertyResolver = getPropertyResolver(context); + return propertyResolver.resolveOrCreateConfigurationProperties(ZookeeperProperties.PREFIX, ZookeeperProperties.class); + }); + // create curator CuratorFactory.registerCurator(registry, null, true, ZookeeperConfigServerBootstrapper::isEnabled);