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**
This commit is contained in:
qxo
2021-08-16 22:00:56 +08:00
committed by GitHub
parent 1c776cc413
commit b647ccb86a
2 changed files with 6 additions and 10 deletions

View File

@@ -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<Applica
private ConfigurableApplicationContext bootstrapServiceContext(ConfigurableEnvironment environment,
final SpringApplication application, String configName) {
StandardEnvironment bootstrapEnvironment = new StandardEnvironment();
ConfigurableEnvironment bootstrapEnvironment = new AbstractEnvironment() {
};
MutablePropertySources bootstrapProperties = bootstrapEnvironment.getPropertySources();
for (PropertySource<?> source : bootstrapProperties) {
bootstrapProperties.remove(source.getName());
}
String configLocation = environment.resolvePlaceholders("${spring.cloud.bootstrap.location:}");
String configAdditionalLocation = environment
.resolvePlaceholders("${spring.cloud.bootstrap.additional-location:}");

View File

@@ -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);
}