Skip to content

Commit 583709f

Browse files
committed
Fixes for ZookeeperConfigServerBootstrapper inconsistencies.
Do not create a property source if CuratorFramework is null in ZookeeperConfigDataLoader. Do not register CuratorFramework twice in CuratorFactory Fixes gh-290
1 parent 599ae49 commit 583709f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

spring-cloud-zookeeper-config/src/main/java/org/springframework/cloud/zookeeper/config/ZookeeperConfigDataLoader.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public ZookeeperConfigDataLoader(Log log) {
4343
public ConfigData load(ConfigDataLoaderContext context, ZookeeperConfigDataResource resource) {
4444
try {
4545
CuratorFramework curator = context.getBootstrapContext().get(CuratorFramework.class);
46+
if (curator == null) {
47+
// this can happen if certain conditions are met
48+
return null;
49+
}
4650
ZookeeperPropertySource propertySource = new ZookeeperPropertySource(resource.getContext(),
4751
curator);
4852
List<ZookeeperPropertySource> propertySources = Collections.singletonList(propertySource);

spring-cloud-zookeeper-core/src/main/java/org/springframework/cloud/zookeeper/CuratorFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ public static void registerCurator(BootstrapRegistry registery, UriComponents lo
117117
BootstrapContext context = event.getBootstrapContext();
118118
if (predicate.test(context)) {
119119
CuratorFramework curatorFramework = context.get(CuratorFramework.class);
120-
event.getApplicationContext().getBeanFactory().registerSingleton("configDataCuratorFramework",
121-
curatorFramework);
120+
if (!event.getApplicationContext().getBeanFactory().containsBean("configDataCuratorFramework")) {
121+
event.getApplicationContext().getBeanFactory().registerSingleton("configDataCuratorFramework",
122+
curatorFramework);
123+
}
122124
}
123125
});
124126

0 commit comments

Comments
 (0)