From e06080e11c2c66e50d748d35e7d55131194a77f3 Mon Sep 17 00:00:00 2001 From: lwpro2 Date: Mon, 5 Apr 2021 16:41:19 +0800 Subject: [PATCH] make the property resolver configurable --- .../PropertySourcesPlaceholderConfigurer.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java b/spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java index abbfec08ab2e..67c54acdc750 100644 --- a/spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java +++ b/spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java @@ -24,13 +24,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.PlaceholderConfigurerSupport; import org.springframework.context.EnvironmentAware; -import org.springframework.core.env.ConfigurablePropertyResolver; -import org.springframework.core.env.Environment; -import org.springframework.core.env.MutablePropertySources; -import org.springframework.core.env.PropertiesPropertySource; -import org.springframework.core.env.PropertySource; -import org.springframework.core.env.PropertySources; -import org.springframework.core.env.PropertySourcesPropertyResolver; +import org.springframework.core.env.*; import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringValueResolver; @@ -154,10 +148,17 @@ public String getProperty(String key) { } } - processProperties(beanFactory, new PropertySourcesPropertyResolver(this.propertySources)); + processProperties(beanFactory, getPropertyResolver(this.propertySources)); this.appliedPropertySources = this.propertySources; } + /** + * Construct and provide a PropertyResolver from the given properties. + */ + public ConfigurablePropertyResolver getPropertyResolver(MutablePropertySources propertySources){ + return new PropertySourcesPropertyResolver(propertySources); + } + /** * Visit each bean definition in the given bean factory and attempt to replace ${...} property * placeholders with values from the given properties.