diff --git a/spring-cloud-config-client/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationListener.java b/spring-cloud-config-client/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationListener.java index a6927992..eab7f6ef 100644 --- a/spring-cloud-config-client/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationListener.java +++ b/spring-cloud-config-client/src/main/java/org/springframework/cloud/bootstrap/encrypt/EnvironmentDecryptApplicationListener.java @@ -15,10 +15,8 @@ */ package org.springframework.cloud.bootstrap.encrypt; -import java.lang.reflect.Field; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -32,7 +30,6 @@ import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; import org.springframework.security.crypto.encrypt.TextEncryptor; -import org.springframework.util.ReflectionUtils; /** * @author Dave Syer @@ -48,20 +45,8 @@ public class EnvironmentDecryptApplicationListener implements private TextEncryptor encryptor; - private Field propertySourcesField; - private boolean failOnError = true; - { - initField(); - } - - private void initField() { - propertySourcesField = ReflectionUtils.findField(CompositePropertySource.class, - "propertySources"); - propertySourcesField.setAccessible(true); - } - public EnvironmentDecryptApplicationListener(TextEncryptor encryptor) { this.encryptor = encryptor; } @@ -131,17 +116,11 @@ public class EnvironmentDecryptApplicationListener implements } else if (source instanceof CompositePropertySource) { - try { - @SuppressWarnings("unchecked") - Set> sources = (Set>) propertySourcesField - .get(source); - for (PropertySource nested : sources) { - decrypt(nested, overrides); - } - } - catch (IllegalAccessException e) { - return; + for (PropertySource nested : ((CompositePropertySource) source) + .getPropertySources()) { + decrypt(nested, overrides); } + } } diff --git a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServerHealthIndicator.java b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServerHealthIndicator.java index 0c598b5d..f2160821 100644 --- a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServerHealthIndicator.java +++ b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServerHealthIndicator.java @@ -1,16 +1,13 @@ package org.springframework.cloud.config.client; +import java.util.ArrayList; +import java.util.List; + import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health.Builder; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.Environment; import org.springframework.core.env.PropertySource; -import org.springframework.util.ReflectionUtils; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; /** * @author Spencer Gibb @@ -31,14 +28,8 @@ public class ConfigServerHealthIndicator extends AbstractHealthIndicator { PropertySource propertySource = locator.locate(env); builder.up(); if (propertySource instanceof CompositePropertySource) { - CompositePropertySource composite = CompositePropertySource.class.cast(propertySource); - Field field = ReflectionUtils.findField(CompositePropertySource.class, - "propertySources"); - field.setAccessible(true); - @SuppressWarnings("unchecked") - Set> propertySources = (Set>) field.get(composite); List sources = new ArrayList<>(); - for (PropertySource ps : propertySources) { + for (PropertySource ps : ((CompositePropertySource) propertySource).getPropertySources()) { sources.add(ps.getName()); } builder.withDetail("propertySources", sources); diff --git a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/RefreshEndpoint.java b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/RefreshEndpoint.java index 64114700..9a44c781 100644 --- a/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/RefreshEndpoint.java +++ b/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/RefreshEndpoint.java @@ -16,7 +16,6 @@ package org.springframework.cloud.config.client; -import java.lang.reflect.Field; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -38,7 +37,6 @@ import org.springframework.core.env.PropertySource; import org.springframework.core.env.StandardEnvironment; import org.springframework.jmx.export.annotation.ManagedOperation; import org.springframework.jmx.export.annotation.ManagedResource; -import org.springframework.util.ReflectionUtils; import org.springframework.web.context.support.StandardServletEnvironment; /** @@ -146,12 +144,7 @@ public class RefreshEndpoint extends AbstractEndpoint> { private void extract(PropertySource parent, Map result) { if (parent instanceof CompositePropertySource) { try { - Field field = ReflectionUtils.findField(CompositePropertySource.class, - "propertySources"); - field.setAccessible(true); - @SuppressWarnings("unchecked") - Set> sources = (Set>) field.get(parent); - for (PropertySource source : sources) { + for (PropertySource source : ((CompositePropertySource) parent).getPropertySources()) { extract(source, result); } } catch (Exception e) {