Uses bootstrap registry for passing complex objects.
This commit is contained in:
@@ -20,6 +20,7 @@ import java.util.Collections;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
|
||||
import org.springframework.boot.context.config.ConfigData;
|
||||
import org.springframework.boot.context.config.ConfigDataLoader;
|
||||
@@ -33,8 +34,10 @@ public class ZookeeperConfigDataLoader implements ConfigDataLoader<ZookeeperConf
|
||||
@Override
|
||||
public ConfigData load(ConfigDataLoaderContext context, ZookeeperConfigDataLocation location) {
|
||||
try {
|
||||
CuratorFramework curator = context.getBootstrapRegistry().getRegistration(CuratorFramework.class)
|
||||
.get();
|
||||
ZookeeperPropertySource propertySource = new ZookeeperPropertySource(location.getContext(),
|
||||
location.getCurator());
|
||||
curator);
|
||||
return new ConfigData(Collections.singletonList(propertySource));
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
@@ -18,29 +18,21 @@ package org.springframework.cloud.zookeeper.config;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
|
||||
import org.springframework.boot.context.config.ConfigDataLocation;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
|
||||
public class ZookeeperConfigDataLocation extends ConfigDataLocation {
|
||||
|
||||
private final CuratorFramework curator;
|
||||
private final ZookeeperConfigProperties properties;
|
||||
private final String context;
|
||||
private final boolean optional;
|
||||
|
||||
public ZookeeperConfigDataLocation(CuratorFramework curator, ZookeeperConfigProperties properties, String context, boolean optional) {
|
||||
this.curator = curator;
|
||||
public ZookeeperConfigDataLocation(ZookeeperConfigProperties properties, String context, boolean optional) {
|
||||
this.properties = properties;
|
||||
this.context = context;
|
||||
this.optional = optional;
|
||||
}
|
||||
|
||||
public CuratorFramework getCurator() {
|
||||
return this.curator;
|
||||
}
|
||||
|
||||
public ZookeeperConfigProperties getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
@@ -62,15 +54,14 @@ public class ZookeeperConfigDataLocation extends ConfigDataLocation {
|
||||
return false;
|
||||
}
|
||||
ZookeeperConfigDataLocation that = (ZookeeperConfigDataLocation) o;
|
||||
return this.curator.equals(that.curator) &&
|
||||
this.properties.equals(that.properties) &&
|
||||
return this.properties.equals(that.properties) &&
|
||||
this.optional == that.optional &&
|
||||
this.context.equals(that.context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.curator, this.properties, this.context);
|
||||
return Objects.hash(this.optional, this.properties, this.context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ZookeeperConfigDataLocationResolver implements ConfigDataLocationRe
|
||||
|
||||
ArrayList<ZookeeperConfigDataLocation> locations = new ArrayList<>();
|
||||
contexts.forEach(propertySourceContext -> locations
|
||||
.add(new ZookeeperConfigDataLocation(curator, properties, propertySourceContext, optional)));
|
||||
.add(new ZookeeperConfigDataLocation(properties, propertySourceContext, optional)));
|
||||
|
||||
return locations;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user