Register ZookeeperProperties in Bootstraper (#331)

Co-authored-by: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com>
This commit is contained in:
Ryan Baxter
2024-03-12 10:23:41 -04:00
committed by GitHub
parent 87cfa5a404
commit 463aaa7881

View File

@@ -35,6 +35,7 @@ import org.springframework.cloud.config.client.ConfigClientProperties;
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 class ZookeeperConfigServerBootstrapper implements BootstrapRegistryIniti
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);