From b647ccb86a4bae21c6207c63a1c2d4a180275bfd Mon Sep 17 00:00:00 2001 From: qxo <49526356@qq.com> Date: Mon, 16 Aug 2021 22:00:56 +0800 Subject: [PATCH] fix: remove unnecessary code (#1000) new StandardEnvironment will add systemProperties/systemEnvironment PropertySource within its constructor which we do not need. **we should not create object which do something we do not want, then undo it** --- .../cloud/bootstrap/BootstrapApplicationListener.java | 8 +++----- .../config/PropertySourceBootstrapConfiguration.java | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java index 1fa08e6b..76e2fba7 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapApplicationListener.java @@ -49,13 +49,13 @@ import org.springframework.context.event.SmartApplicationListener; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.Order; +import org.springframework.core.env.AbstractEnvironment; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySource.StubPropertySource; -import org.springframework.core.env.StandardEnvironment; import org.springframework.core.env.SystemEnvironmentPropertySource; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -141,11 +141,9 @@ public class BootstrapApplicationListener implements ApplicationListener source : bootstrapProperties) { - bootstrapProperties.remove(source.getName()); - } String configLocation = environment.resolvePlaceholders("${spring.cloud.bootstrap.location:}"); String configAdditionalLocation = environment .resolvePlaceholders("${spring.cloud.bootstrap.additional-location:}"); diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java index 1822e5bc..f3a7439c 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java @@ -43,13 +43,13 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.core.annotation.AnnotationAwareOrderComparator; +import org.springframework.core.env.AbstractEnvironment; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.Environment; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; -import org.springframework.core.env.StandardEnvironment; import org.springframework.util.StringUtils; import static org.springframework.core.env.StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME; @@ -202,10 +202,8 @@ public class PropertySourceBootstrapConfiguration } private Environment environment(MutablePropertySources incoming) { - StandardEnvironment environment = new StandardEnvironment(); - for (PropertySource source : environment.getPropertySources()) { - environment.getPropertySources().remove(source.getName()); - } + ConfigurableEnvironment environment = new AbstractEnvironment() { + }; for (PropertySource source : incoming) { environment.getPropertySources().addLast(source); }