Removes RelaxedPropertyResolver
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.client.circuitbreaker;
|
||||
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.cloud.commons.util.SpringFactoryImportSelector;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@@ -31,7 +30,7 @@ public class EnableCircuitBreakerImportSelector extends
|
||||
|
||||
@Override
|
||||
protected boolean isEnabled() {
|
||||
return new RelaxedPropertyResolver(getEnvironment()).getProperty(
|
||||
return getEnvironment().getProperty(
|
||||
"spring.cloud.circuit.breaker.enabled", Boolean.class, Boolean.TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.client.discovery;
|
||||
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.cloud.commons.util.SpringFactoryImportSelector;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
@@ -54,7 +53,7 @@ public class EnableDiscoveryClientImportSelector
|
||||
|
||||
@Override
|
||||
protected boolean isEnabled() {
|
||||
return new RelaxedPropertyResolver(getEnvironment()).getProperty(
|
||||
return getEnvironment().getProperty(
|
||||
"spring.cloud.discovery.enabled", Boolean.class, Boolean.TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.springframework.cloud.commons.util;
|
||||
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.core.env.PropertyResolver;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -12,19 +11,18 @@ public class IdUtils {
|
||||
private static final String SEPARATOR = ":";
|
||||
|
||||
public static String getDefaultInstanceId(PropertyResolver resolver) {
|
||||
RelaxedPropertyResolver relaxed = new RelaxedPropertyResolver(resolver);
|
||||
String vcapInstanceId = relaxed.getProperty("vcap.application.instance_id");
|
||||
String vcapInstanceId = resolver.getProperty("vcap.application.instance_id");
|
||||
if (StringUtils.hasText(vcapInstanceId)) {
|
||||
return vcapInstanceId;
|
||||
}
|
||||
|
||||
String hostname = relaxed.getProperty("spring.cloud.client.hostname");
|
||||
String appName = relaxed.getProperty("spring.application.name");
|
||||
String hostname = resolver.getProperty("spring.cloud.client.hostname");
|
||||
String appName = resolver.getProperty("spring.application.name");
|
||||
|
||||
String namePart = combineParts(hostname, SEPARATOR, appName);
|
||||
|
||||
String indexPart = relaxed.getProperty("spring.application.instance_id",
|
||||
relaxed.getProperty("server.port"));
|
||||
String indexPart = resolver.getProperty("spring.application.instance_id",
|
||||
resolver.getProperty("server.port"));
|
||||
|
||||
return combineParts(namePart, SEPARATOR, indexPart);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.LocalManagementPort;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.context.embedded.LocalServerPort;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.bind.PropertySourcesPropertyValues;
|
||||
import org.springframework.boot.bind.RelaxedDataBinder;
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.boot.context.config.ConfigFileApplicationListener;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.logging.LogFile;
|
||||
@@ -51,6 +50,8 @@ import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.cloud.env.EnvironmentUtils.getSubProperties;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -114,8 +115,7 @@ public class PropertySourceBootstrapConfiguration implements
|
||||
|
||||
private void reinitializeLoggingSystem(ConfigurableEnvironment environment,
|
||||
String oldLogConfig, LogFile oldLogFile) {
|
||||
Map<String, Object> props = new RelaxedPropertyResolver(environment)
|
||||
.getSubProperties("logging.");
|
||||
Map<String, Object> props = getSubProperties(environment, "logging.");
|
||||
if (!props.isEmpty()) {
|
||||
String logConfig = environment.resolvePlaceholders("${logging.config:}");
|
||||
LogFile logFile = LogFile.get(environment);
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.bootstrap.encrypt.KeyProperties.KeyStore;
|
||||
import org.springframework.cloud.context.encrypt.EncryptorFactory;
|
||||
@@ -110,22 +109,21 @@ public class EncryptionBootstrapConfiguration {
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
Environment environment = context.getEnvironment();
|
||||
RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(environment);
|
||||
if (hasProperty(propertyResolver, environment, "encrypt.keyStore.location")) {
|
||||
if (hasProperty(propertyResolver, environment, "encrypt.keyStore.password")) {
|
||||
if (hasProperty(environment, "encrypt.keyStore.location")) {
|
||||
if (hasProperty(environment, "encrypt.keyStore.password")) {
|
||||
return ConditionOutcome.match("Keystore found in Environment");
|
||||
}
|
||||
return ConditionOutcome
|
||||
.noMatch("Keystore found but no password in Environment");
|
||||
}
|
||||
else if (hasProperty(propertyResolver, environment, "encrypt.key")) {
|
||||
else if (hasProperty(environment, "encrypt.key")) {
|
||||
return ConditionOutcome.match("Key found in Environment");
|
||||
}
|
||||
return ConditionOutcome.noMatch("Keystore nor key found in Environment");
|
||||
}
|
||||
|
||||
private boolean hasProperty(RelaxedPropertyResolver propertyResolver, Environment environment, String key) {
|
||||
String value = propertyResolver.getProperty(key);
|
||||
private boolean hasProperty(Environment environment, String key) {
|
||||
String value = environment.getProperty(key);
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
44
spring-cloud-context/src/main/java/org/springframework/cloud/env/EnvironmentUtils.java
vendored
Normal file
44
spring-cloud-context/src/main/java/org/springframework/cloud/env/EnvironmentUtils.java
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
package org.springframework.cloud.env;
|
||||
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.EnumerablePropertySource;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.env.PropertySources;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class EnvironmentUtils {
|
||||
public static Map<String, Object> getSubProperties(Environment environment, String keyPrefix) {
|
||||
if (environment instanceof ConfigurableEnvironment) {
|
||||
ConfigurableEnvironment env = (ConfigurableEnvironment) environment;
|
||||
Map<String, Object> subProperties = new LinkedHashMap<>();
|
||||
PropertySources propertySources = env.getPropertySources();
|
||||
for (PropertySource<?> source : propertySources) {
|
||||
if (source instanceof EnumerablePropertySource) {
|
||||
for (String name : ((EnumerablePropertySource<?>) source)
|
||||
.getPropertyNames()) {
|
||||
String key = getSubKey(name, keyPrefix);
|
||||
if (key != null && !subProperties.containsKey(key)) {
|
||||
subProperties.put(key, source.getProperty(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableMap(subProperties);
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
private static String getSubKey(String name, String keyPrefix) {
|
||||
if (name.startsWith(keyPrefix)) {
|
||||
return name.substring(keyPrefix.length());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||
import org.springframework.boot.logging.LogLevel;
|
||||
import org.springframework.boot.logging.LoggingSystem;
|
||||
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
|
||||
@@ -28,6 +27,8 @@ import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import static org.springframework.cloud.env.EnvironmentUtils.getSubProperties;
|
||||
|
||||
/**
|
||||
* Listener that looks for {@link EnvironmentChangeEvent} and rebinds logger levels if any
|
||||
* changed.
|
||||
@@ -57,8 +58,7 @@ public class LoggingRebinder
|
||||
}
|
||||
|
||||
protected void setLogLevels(LoggingSystem system, Environment environment) {
|
||||
Map<String, Object> levels = new RelaxedPropertyResolver(environment)
|
||||
.getSubProperties("logging.level.");
|
||||
Map<String, Object> levels = getSubProperties(environment, "logging.level.");
|
||||
for (Entry<String, Object> entry : levels.entrySet()) {
|
||||
setLogLevel(system, environment, entry.getKey(), entry.getValue().toString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user