update configuration properties to customize settings

This commit is contained in:
Spencer Gibb
2015-07-29 16:11:15 -06:00
parent 3d66823d62
commit 978165310a
2 changed files with 12 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ package org.springframework.cloud.zookeeper.config;
import lombok.Data;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
@@ -13,4 +14,10 @@ public class ZookeeperConfigProperties {
private boolean enabled = true;
private String root = "config";
@NotEmpty
private String defaultContext = "application";
@NotEmpty
private String profileSeparator = ",";
}

View File

@@ -2,6 +2,7 @@ package org.springframework.cloud.zookeeper.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.annotation.PreDestroy;
@@ -35,7 +36,7 @@ public class ZookeeperPropertySourceLocator implements PropertySourceLocator {
String root = properties.getRoot();
List<String> contexts = new ArrayList<>();
String defaultContext = root + "/application";
String defaultContext = root + "/" + properties.getDefaultContext();
contexts.add(defaultContext);
addProfiles(contexts, defaultContext, profiles);
@@ -45,6 +46,8 @@ public class ZookeeperPropertySourceLocator implements PropertySourceLocator {
CompositePropertySource composite = new CompositePropertySource("zookeeper");
Collections.reverse(contexts);
for (String propertySourceContext : contexts) {
ZookeeperPropertySource propertySource = create(propertySourceContext);
propertySource.start();
@@ -69,7 +72,7 @@ public class ZookeeperPropertySourceLocator implements PropertySourceLocator {
private void addProfiles(List<String> contexts, String baseContext,
List<String> profiles) {
for (String profile : profiles) {
contexts.add(baseContext + "::" + profile);
contexts.add(baseContext + properties.getProfileSeparator() + profile);
}
}
}